JavaScript函数更改属性的值

时间:2015-03-23 19:56:23

标签: javascript php html

我有这行代码,其值为id = 0061237

<a id="DeleteButton" href="#" onclick="DeleteMovie(0061237);" >
    <button  class="btn btn-danger">Delete Movie</button>
</a>

当它传递给JavaScript函数时,它将其参数值更改为 25247 。只有一些值发生这种情况,对于其他值,这是正常的吗?

JavaScript函数:

function DeleteMovie(MovieID) {
    var ConfirmDelete = confirm('Do You Really Want To Delete Movie?');
    if (ConfirmDelete == true)
        location.replace("Delete.php?MovieID="+MovieID);
}

2 个答案:

答案 0 :(得分:5)

那是因为在JavaScript中,带有前导零的数字被视为八进制,而在十进制中,您的数字将被转换为25247.

尝试将其作为字符串传递:onclick="DeleteMovie('0061237');"

Ref:&#34;在整数字面上前导0(零)表示它是八进制。&#34;

答案 1 :(得分:2)

尝试将ID放在&#39; 0061237&#39;

之间
<a id="DeleteButton" href="#" onclick="DeleteMovie('0061237');" >
    <button  class="btn btn-danger">Delete Movie</button>
</a>
function DeleteMovie(MovieID) {
    var ConfirmDelete = confirm('Do You Really Want To Delete Movie?');
    if (ConfirmDelete == true)
        location.replace("Delete.php?MovieID="+MovieID);
}