Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.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 mobile干扰javascript填充选择框_Javascript_Html_Css_Jquery Mobile_Html Select - Fatal编程技术网

Jquery mobile干扰javascript填充选择框

Jquery mobile干扰javascript填充选择框,javascript,html,css,jquery-mobile,html-select,Javascript,Html,Css,Jquery Mobile,Html Select,我正在尝试使用javascript以编程方式填充html选择框。我发现,尽管我的代码正常工作,但jquery mobile干扰了选择框中显示的内容。我正在设置所选选项,该选项正在工作,但选择框中显示的值是错误的值。它并没有改变我最初用html填充的内容 我正在链接到“”。还有什么可以绕过jquery的吗?我不能仅仅删除jquery css。这会破坏我网站上的一切,我没有时间全部重做 以下是问题的一个方面: 以下是我的代码供参考: 下面是填充选择框的javascript函数: function p

我正在尝试使用javascript以编程方式填充html选择框。我发现,尽管我的代码正常工作,但jquery mobile干扰了选择框中显示的内容。我正在设置所选选项,该选项正在工作,但选择框中显示的值是错误的值。它并没有改变我最初用html填充的内容

我正在链接到“”。还有什么可以绕过jquery的吗?我不能仅仅删除jquery css。这会破坏我网站上的一切,我没有时间全部重做

以下是问题的一个方面:

以下是我的代码供参考:

下面是填充选择框的javascript函数:

function printCartList(newCart){
    // newCart is an optional parameter. Check to see if it is given.
    newCart = newCart ? newCart : "a_new_cart_was_not_provided_12345abcde";

    // Create a cart list from the stored cookie if it exists, otherwise create a new one.
    if($.cookie("carts") != null){
        carts = JSON.parse($.cookie("carts"));
    }
    else{
        selectOption = new Object();
        selectOption.value = "newuniquecartid12345abcde";
        selectOption.html = "***New Cart***";
        carts = new Object();
        carts.size = 1;
        carts.option = new Array();
        carts.option[0] = selectOption;
    }

    // Get the select box
    var select = document.getElementById("select_cart");

    // Get the number of options in the select box.
    var length = select.options.length;

    // Remove all of the options in the select box.
    while(select.options.length > 0){
        select.remove(0);
    }


    // If there is a new cart, add it to the cart.
    if(newCart != "a_new_cart_was_not_provided_12345abcde"){
        selectOption = new Object();
        selectOption.value = newCart;
        selectOption.html = newCart;
        carts.option[carts.size] = selectOption;
        carts.size++;
    }
    // Save the cart in a cookie
    $.cookie("carts",JSON.stringify(carts));

    // Populate the select box
    for(var i = 0; i < carts.size; i++){
        var opt = document.createElement('option');
        opt.value = carts.option[i].value;
        opt.innerHTML = carts.option[i].html;
        if($.cookie("activeCart") == carts.option[i].value && newCart != "a_new_cart_was_not_provided_12345abcde"){
            // Set the selected value
            alert(carts.option[i].value);
            opt.selected = true;
            // I tried changing the value of a p tag inside the default option, but that didn't work
            document.getElementById("selectHTML").innerHTML = carts.option[i].html;
        }
        if(opt.value == "dd"){alert("hi");};
        select.appendChild(opt);
    }   

}
函数printCartList(newCart){
//newCart是一个可选参数。请检查是否给定了该参数。
newCart=newCart?newCart:“未提供新的购物车\u 12345abcde”;
//从存储的cookie创建购物车列表(如果存在),否则创建一个新的购物车列表。
如果($.cookie(“carts”)!=null){
carts=JSON.parse($.cookie(“carts”);
}
否则{
selectOption=newobject();
selectOption.value=“newuniquecartid12345abcde”;
selectOption.html=“***新购物车***”;
carts=新对象();
推车尺寸=1;
carts.option=新数组();
carts.option[0]=selectOption;
}
//获取选择框
var select=document.getElementById(“选择购物车”);
//获取“选择”框中的选项数。
变量长度=select.options.length;
//删除“选择”框中的所有选项。
while(选择.options.length>0){
选择。删除(0);
}
//如果有新购物车,请将其添加到购物车。
if(newCart!=“未提供新的购物车”\u 12345abcde”){
selectOption=newobject();
选择option.value=newCart;
selectOption.html=newCart;
carts.option[carts.size]=选择选项;
手推车.尺寸++;
}
//将购物车保存在cookie中
$.cookie(“carts”,JSON.stringify(carts));
//填充选择框
对于(变量i=0;i
这是我的html:

<form method="POST" name="cartSelectForm" action="home.php">
    <select name="cartList" id="select_cart" data-mini="true" onchange="submitCartForm()" data-icon="false">
        <option value="newuniquecartid1234567890"><p id="selectHTML">*** New Cart ***</p></option>
    </select>
</form>

***新购物车***


任何帮助都将不胜感激。

我知道这个问题大约有一个月了,但我偶然发现了它,因为我遇到了完全相同的问题。我最终通过这样做修复了它:

在以编程方式设置该值之后,我在该选择框上手动触发了更改事件。我猜这迫使jQuery mobile更新了与该元素相关的所有增强标记。有点烦人,但幸运的是很容易处理

$("#country").val("US");
$("#country").change();
希望这能帮助别人