需求:获取{ "title": "付款金额", "data": "payment_amount", "className": "edit_text", "visible": true, "render": { "display": function(data, type, row, meta) { return '<input name="idata' + row.rowMark + '[' + meta.row + '][' + meta.col + ']" class="read_input only_num num_cut payment_amount" type="text" hide_value="' + data + '" value="' + data + '"required />'; } } }用on change 监听值是否改变,获取payment_amount改变后的值赋给new_num
时间: 2023-07-21 11:10:41 浏览: 55
要实现你的需求,可以使用以下代码来监听付款金额输入框值的变化,并将新值赋给 `new_num` 变量:
```javascript
var new_num = ""; // 初始化 new_num 变量
// 监听付款金额输入框值的变化
$(document).on("change", "input[name='payment_amount']", function() {
new_num = $(this).val(); // 将新值赋给 new_num 变量
console.log("新的付款金额值:" + new_num);
});
```
在这个例子中,我们使用了 jQuery 的 `on` 方法来监听文档中所有名称为 "payment_amount" 的输入框的 `change` 事件。当输入框的值发生改变时,回调函数会被触发。在回调函数中,我们使用 `$(this).val()` 来获取输入框的新值,并将其赋给 `new_num` 变量。你可以根据需要在回调函数中进行其他操作。
请注意,为了确保监听到动态添加的输入框,我们将事件绑定到了文档(`$(document)`)上,并通过选择器 `"input[name='payment_amount']"` 来指定要监听的输入框。
相关问题
jsx函数组件中获取多个相同class,然后样式修改为display:none
可以使用React的Hooks来实现:
首先,使用`useRef`创建一个ref对象,用于保存需要修改样式的DOM节点。
然后,在函数组件中使用`useEffect`钩子函数,通过`querySelectorAll`方法获取所有相同class的DOM节点,并将其保存到ref对象中。
最后,在ref对象更新后,再次使用`querySelectorAll`方法获取所有相同class的DOM节点,并将它们的样式修改为`display:none`。
示例代码如下:
```jsx
import React, { useRef, useEffect } from 'react';
function MyComponent() {
const myRef = useRef(null);
useEffect(() => {
const nodes = document.querySelectorAll('.my-class');
myRef.current = nodes;
}, []);
useEffect(() => {
if (myRef.current) {
const nodes = document.querySelectorAll('.my-class');
nodes.forEach(node => node.style.display = 'none');
}
}, [myRef.current]);
return (
<div>
{/* some content */}
<div className="my-class">one</div>
<div className="my-class">two</div>
<div className="my-class">three</div>
{/* more content */}
</div>
);
}
```
NameError: name '_Disk__name_' is not defined
This error occurs when you try to access a private attribute or method of a class in Python. In this case, it seems like you are trying to access the private attribute `__name__` of a class called `_Disk`.
In Python, any attribute or method that starts with two underscores is considered private and cannot be accessed from outside the class. However, Python does not actually prevent you from accessing these attributes or methods. Instead, it mangles the name by adding `_ClassName` before the attribute name, where `ClassName` is the name of the class.
So, in order to access the private attribute `__name__` of the `_Disk` class, you should use the mangled name `_Disk__name__`.
For example:
```
class _Disk:
def __init__(self, name):
self.__name__ = name
disk = _Disk("MyDisk")
print(disk._Disk__name__) # Output: "MyDisk"
```
Note that accessing private attributes or methods is generally not recommended as it can make your code harder to maintain and debug. If possible, you should use public attributes and methods instead.
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)