Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.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不更新span_Jquery_Html - Fatal编程技术网

jQuery不更新span

jQuery不更新span,jquery,html,Jquery,Html,我正在使用jQuery更新span内容,但它不起作用 我已经包括了下面的所有内容,尽管我确信只有这个不起作用: $("#YouGet").html(StringToGoIn); ---Html--- 而不是 $("span#YouGet").html(StringToGoIn); 有什么原因吗?去掉转义符id=“YouGet”works您正在转义id名称中的引号字符。因此,span的id是“YouGet”,而不是YouGet。从HTML中的引号中删除转义。 这似乎有效。HTML中的引号被转

我正在使用jQuery更新span内容,但它不起作用

我已经包括了下面的所有内容,尽管我确信只有这个不起作用:

$("#YouGet").html(StringToGoIn);
---Html---

而不是

$("span#YouGet").html(StringToGoIn);

有什么原因吗?

去掉转义符
id=“YouGet”
works

您正在转义id名称中的引号字符。因此,span的id是
“YouGet”
,而不是
YouGet
。从HTML中的引号中删除转义。


这似乎有效。

HTML中的引号被转义的原因是什么?这可能是造成问题的原因。此外,使用
$('#YouGet')
比使用上述任何选项都好,因为ID是唯一的,所以跨度部分是不相关的。框9是正确的。删除斜杠后,您的代码就可以运行了。@Box9,您应该将您的评论变成一个答案,因为这实际上就是问题所在,@Serge,谢谢您的确认。至于回答,我会让下面的正确答案中的一个获得代表;)谢谢,伙计们,我现在觉得自己像个十足的白痴,哈哈。这是PHP脚本的一部分,因此是逃跑。
    function IsNumeric(strString)
//  check for valid numeric strings    
{
    var strValidChars = "0123456789.-";
    var strChar;
    var blnResult = true;

    if (strString.length === 0) {
        return false;
    }

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult === true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}



function CutCalculator() {

    var Value = $('#CostField').val();

    if (IsNumeric(Value) === false) {
        alert("You didn't enter a valid value");
    }
    else {

        Value = parseFloat(Value);

        var Split = 0.5;
        var SupplierGets = Value * Split;
        var StringToGoIn = "&pound;" + SupplierGets;

        // alert(StringToGoIn );   <--- works fine
        // ---- WHY IS THIS NOT WORKING?!?! - URGH!!!
        $("#YouGet").html(StringToGoIn);

    }

}
$('span[id=YouGet]').html(data);
$("span#YouGet").html(StringToGoIn);