我想选择控件中的第一个选项,因此我编写了以下代码:
$("#MySelect").val($("#MySelect option:first").val());
现在,请将以下内容复制并粘贴到Google Closure Compiler中:
// ==ClosureCompiler==
// @output_file_name default.js
// @compilation_level ADVANCED_OPTIMIZATIONS
// @externs_url http://closure-compiler.googlecode.com/svn/trunk/contrib/externs/jquery-1.7.js
// ==/ClosureCompiler==
$("#MySelect").val($("#MySelect option:first").val());
你会得到这个错误:
感谢您的建议。
$("#MySelect").prop("selectedIndex", 0 )
- Esailija.val()
方法可能会返回一个与外部.val()
方法期望的参数类型不匹配的类型。例如,如果它返回了一个jQuery
对象,那就是不正确的 - 当然,我们知道.val()
只有在使用参数调用时才会返回一个jQuery
对象,所以在您的代码中,内部的.val()
永远不会发生这种情况... - nnnnnnindex()
而不是val()
。 - wirey00