JavaScript从字符串中减去元素

Iva*_*vic 0 javascript c#

我发送到C#的JavaScript函数字符串是"11-2-2013",并期望在JavaScript函数中使用该字符串,但我在11 - 2 - 2013 = -2004门控.

C#代码:

string id = 11 + '-' + 2 + '-' + 2013;
textBoxBO.Attributes.Add("onblur", "TextBoxReset(this," + id + ")");
Run Code Online (Sandbox Code Playgroud)

JavaScript代码:

function TextBoxReset(txt, ID) {
    if (txt.value > 0) {
        var textBoxRR = document.getElementById("ContentPlaceHolder1_txtRR" + ID);
        textBoxRR.value = 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

如何告诉JavaScript不要从该字符串中减去元素.

Amb*_*mps 6

你必须把日期放在引号中:

textBoxBO.Attributes.Add("onblur", "TextBoxReset(this,\"" + id  + "\")");
Run Code Online (Sandbox Code Playgroud)

如果你没有把它放在引号中,它将被渲染为TextBoxReset(this, 11-2-2013),这将导致-2004.