Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 将值指定给选择框_Jquery - Fatal编程技术网

Jquery 将值指定给选择框

Jquery 将值指定给选择框,jquery,Jquery,您好,我在jquery中有一个字符串为“星期二”的变量,我还有一个包含一周中所有日期的选择框,我如何分配我的变量,以便选择框自动选择我的变量?var yourselectvalue='teday'; var yourselectvalue = 'tuesday'; var selectobject=document.getElementById("yourselectboxid") for (var i=0; i<selectobject.length; i++){

您好,我在jquery中有一个字符串为“星期二”的变量,我还有一个包含一周中所有日期的选择框,我如何分配我的变量,以便选择框自动选择我的变量?

var yourselectvalue='teday';
var yourselectvalue = 'tuesday';    
var selectobject=document.getElementById("yourselectboxid")

for (var i=0; i<selectobject.length; i++){
        if (selectobject.options[i].value == yourselectvalue) {
            selectobject.options[i].selected = true;
        }
    }
var selectobject=document.getElementById(“yourselectboxid”) 对于(var i=0;i您可以使用:

例如:

​$('select').val("Tuesday");​​​​​​​​​​​​