简体   繁体   English

JavaScript函数更改属性的值

[英]JavaScript function changing value of an attribute

I have this line of code which has value of id= 0061237 我有这行代码的ID = 0061237的

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

When it is passed to a JavaScript function, it is changing its parameter value to 25247 . 当将其传递给JavaScript函数时,它将其参数值更改为25247 This is happening with only some values, for other values this is working fine? 只有某些值会发生这种情况,对于其他值,这是否正常?

The JavaScript function: JavaScript函数:

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

That's because in JavaScript, numbers with leading zeros are treated as octal, and in decimal, your number would convert to 25247. 这是因为在JavaScript中,前导零的数字被视为八进制,而在十进制中,您的数字将转换为25247。

Try passing it as a string: onclick="DeleteMovie('0061237');" 尝试将其作为字符串传递: onclick="DeleteMovie('0061237');"

Ref : "Leading 0 (zero) on an integer literal indicates it is in octal." 参考 :“整数文字前导0(零)表示它为八进制。”

try to put id between '0061237' 尝试将ID放在'0061237'之间

<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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用javascript更改属性的值 - Changing the Value of an Attribute using javascript 玩笑测试并使用JavaScript更改属性值 - Jest testing and changing attribute value using JavaScript 使用javascript更改锚点的下载属性的值 - Changing the value of the download attribute of an anchor with javascript Javascript函数改变返回值 - Javascript function changing return value Javascript函数不会改变元素的值 - Javascript function not changing value of element 本地存储作为Javascript函数属性值 - Localstorage as Javascript function attribute value JavaScript 通过搜索另一个自定义属性来更改自定义属性的值 - JavaScript changing value of custom attribute by searching another custom attribute JavaScript-更改父级属性值时,子级属性值会自动更改 - JavaScript - Child attribute value is automatically changing when changing parent attribute value HTML属性值通过javascript更改后返回其初始值 - HTML attribute value return to its initial value after changing it by javascript JavaScript:element.setAttribute(attribute,value),element.attribute = value和element。[attribute] = value不会更改属性值 - JavaScript: element.setAttribute(attribute,value) , element.attribute=value & element.[attribute]=value not changing attribute value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM