Javascript 如何更改自己定义的属性

Javascript 如何更改自己定义的属性,javascript,jquery,html,Javascript,Jquery,Html,我想知道如何使用JavaScript/jQuery更改html标记中自己定义的属性。 例如: 我定义了一种称为升序的属性: <th ascending="true" id="1">some text</th> 您可以使用“setAttribute”方法 如下所示:tag.setAttribute(“升序”、“假”) 您可以使用“setAttribute”方法 如下所示:tag.setAttribute(“升序”、“假”) 您可以使用“setAttribute”方法 如下

我想知道如何使用JavaScript/jQuery更改html标记中自己定义的属性。 例如: 我定义了一种称为升序的属性:

<th ascending="true" id="1">some text</th>
您可以使用“setAttribute”方法

如下所示:tag.setAttribute(“升序”、“假”)

您可以使用“setAttribute”方法

如下所示:tag.setAttribute(“升序”、“假”)

您可以使用“setAttribute”方法

如下所示:tag.setAttribute(“升序”、“假”)

您可以使用“setAttribute”方法


如下所示:tag.setAttribute(“升序”、“假”)

添加自定义时使用自定义
数据-*
属性,否则无法通过验证!就你而言:

<th data-ascending="true" id="1">some text</th>
jQuery:

$("#1").data("ascending"); //get
$("#1").data("ascending", true); //set

添加自定义时使用自定义
数据-*
属性,否则无法通过验证!就你而言:

<th data-ascending="true" id="1">some text</th>
jQuery:

$("#1").data("ascending"); //get
$("#1").data("ascending", true); //set

添加自定义时使用自定义
数据-*
属性,否则无法通过验证!就你而言:

<th data-ascending="true" id="1">some text</th>
jQuery:

$("#1").data("ascending"); //get
$("#1").data("ascending", true); //set

添加自定义时使用自定义
数据-*
属性,否则无法通过验证!就你而言:

<th data-ascending="true" id="1">some text</th>
jQuery:

$("#1").data("ascending"); //get
$("#1").data("ascending", true); //set
在jquery中试试这个

$(function(){
  $('#1').attr('ascending',false);
});
但是您应该使用.prop()

或者使用javascript

function changeValue() {
  var tag = getElemendById('1');
  tag.setAttribute('ascending', false);
}
javascript版本的html应如下所示:

<th onLoad="changeValue()" data-ascending="true" id="1">some text</th>
一些文本
我没有测试它,但它应该可以工作;)

在jquery中试试这个

$(function(){
  $('#1').attr('ascending',false);
});
但是您应该使用.prop()

或者使用javascript

function changeValue() {
  var tag = getElemendById('1');
  tag.setAttribute('ascending', false);
}
javascript版本的html应如下所示:

<th onLoad="changeValue()" data-ascending="true" id="1">some text</th>
一些文本
我没有测试它,但它应该可以工作;)

在jquery中试试这个

$(function(){
  $('#1').attr('ascending',false);
});
但是您应该使用.prop()

或者使用javascript

function changeValue() {
  var tag = getElemendById('1');
  tag.setAttribute('ascending', false);
}
javascript版本的html应如下所示:

<th onLoad="changeValue()" data-ascending="true" id="1">some text</th>
一些文本
我没有测试它,但它应该可以工作;)

在jquery中试试这个

$(function(){
  $('#1').attr('ascending',false);
});
但是您应该使用.prop()

或者使用javascript

function changeValue() {
  var tag = getElemendById('1');
  tag.setAttribute('ascending', false);
}
javascript版本的html应如下所示:

<th onLoad="changeValue()" data-ascending="true" id="1">some text</th>
一些文本

我没有测试它,但它应该可以工作;)

如果你使用jQuery,你可能想考虑使用数据属性而不是定义自定义属性:你不应该使用你自己制作的属性。改为查看数据属性。对于
标记。升序
升序
是一个属性。了解属性和属性之间的区别。如果使用jQuery,可能需要考虑使用数据属性,而不是定义自定义属性:不应该使用自己的编译属性。改为查看数据属性。对于
标记。升序
升序
是一个属性。了解属性和属性之间的区别。如果使用jQuery,可能需要考虑使用数据属性,而不是定义自定义属性:不应该使用自己的编译属性。改为查看数据属性。对于
标记。升序
升序
是一个属性。了解属性和属性之间的区别。如果使用jQuery,可能需要考虑使用数据属性,而不是定义自定义属性:不应该使用自己的编译属性。改为查看数据属性。对于
标记。升序
升序
是一个属性。了解属性和属性之间的区别。