A demo for sharing data between an input (id=obHid) and a textarea (id=idField)
用于在输入(id = obHid)和textarea(id = idField)之间共享数据的演示
if($.browser.msie)
$("#"+idField).text($("#obHid").val()); // IE
else
$("#"+idField).attr("value", $("#obHid").val()); // FF
Iskrahelk,
1 个解决方案
#1
2
Don't use either of those methods, and especially don't use browser sniffing. Touching $.browser
is almost always a mistake.
不要使用这些方法中的任何一种,尤其是不要使用浏览器嗅探。触摸$ .browser几乎总是一个错误。
The proper way to read and write form field values in jQuery is val()
. It doesn't matter whether the form field involved is an <input type="text">
or a <textarea>
, they'll both work the same.
在jQuery中读取和写入表单字段值的正确方法是val()。涉及的表单字段是还是
$('#'+idField).val($("#obHid").val());
[Aside: however this will break if idField
may contain dots, as in a selector string they'll turn into class selectors. If that's a concern just use the plain JavaScript version:
[旁白:但是如果idField可能包含点,这会破坏,因为在选择器字符串中它们将变成类选择器。如果这是一个问题,只需使用纯JavaScript版本:
document.getElementById(idField).value= document.getElementById('obHid').value;
a bit wordier, but more straightforward.]
有点讽刺,但更直接。]
#1
2
Don't use either of those methods, and especially don't use browser sniffing. Touching $.browser
is almost always a mistake.
不要使用这些方法中的任何一种,尤其是不要使用浏览器嗅探。触摸$ .browser几乎总是一个错误。
The proper way to read and write form field values in jQuery is val()
. It doesn't matter whether the form field involved is an <input type="text">
or a <textarea>
, they'll both work the same.
在jQuery中读取和写入表单字段值的正确方法是val()。涉及的表单字段是还是
$('#'+idField).val($("#obHid").val());
[Aside: however this will break if idField
may contain dots, as in a selector string they'll turn into class selectors. If that's a concern just use the plain JavaScript version:
[旁白:但是如果idField可能包含点,这会破坏,因为在选择器字符串中它们将变成类选择器。如果这是一个问题,只需使用纯JavaScript版本:
document.getElementById(idField).value= document.getElementById('obHid').value;
a bit wordier, but more straightforward.]
有点讽刺,但更直接。]