通常我$("#id").val()
用来返回所选选项的值,但这次它不起作用.所选标签具有IDaioConceptName
HTML代码
<label>Name</label>
<input type="text" name="name" />
<select id="aioConceptName">
<option>choose io</option>
<option>roma</option>
<option>totti</option>
</select>
Run Code Online (Sandbox Code Playgroud) 以下代码有效:
$("#select-id").change(function(){
var cur_value = $('#select-id option:selected').text();
. . .
});
Run Code Online (Sandbox Code Playgroud)
如何重构第二行:
var cur_value = $(this).***option-selected***.text();
Run Code Online (Sandbox Code Playgroud)
你用的是***option-selected***
什么?
<select id="sel">
<option id="1">aa</option>
<option id="2">bb</option>
<option id="3">cc</option>
</select>
$("#sel").change(function(){
alert($(this).children().attr('id'))
})
Run Code Online (Sandbox Code Playgroud)
现场: http ://jsfiddle.net/cxWVP/
我如何获得当前选择的选项ID?现在总是告诉我id ="1".
考虑:
> function hello(what) {
. what = "world";
. return "Hello, " + arguments[0] + "!";
. }
> hello("shazow")
"Hello, world!"
Run Code Online (Sandbox Code Playgroud)
为什么改变价值what
变化的价值arguments[0]
?
我对jQuery提交功能有一些疑问.
这是工作环境
jQuery:1.7.2,chrome(18.0.1025.168 m).
有两个问题.
第一名:
我的代码是这样的
HTML
<form id="test" action="..." method="post">
<input type="text" />
<input type="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
jQuery的
$('#test').submit(function(){
return false;
})
Run Code Online (Sandbox Code Playgroud)
问题是它在firefox和opera中工作得很好但是chrome.
2ST:
html:如上所述.
jQuery的:
$('#test').submit(function(){
if(...)
alert(something..);
return false;
})
Run Code Online (Sandbox Code Playgroud)
它不适用于firefox,opera和chrome.它总是触发form.submit为什么.
我很困惑.谁能想出来谢谢!
这看起来很奇怪......
我有一些JSON ......
{"firstName":"David","lastName":"Smith","email":null,"id":0}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试解析它并将其与...一起使用时
<script>
$(document).ready(function() {
var json = $.getJSON('userManagement/getUser');
$("p").text(json.firstName);
});
</script>
This is the user management view
Users : <p></p>
Run Code Online (Sandbox Code Playgroud)
什么都没有出现,但如果我只做$("p").text(json); 它告诉我它是一个对象,我可以看到JSON在firebug中是正确的,任何想法?