어떻게 다운로드합니까 데이터 id 속성용? # 39, m ' ()' 방식을 사용하여 i& 오언 재 바인드 정렬할지 클릭 행사를 할 수 있습니다.
<! - begin 스니핏: js 숨기십시오: 거짓값 콘솔: 진정한 바벨. > 거짓값 -;
$("#list li").on('click', function() {
// ret = DetailsView.GetProject($(this).attr("#data-id"), OnComplete, OnTimeOut, OnError);
alert($(this).attr("#data-id"));
});
,,, /script> < > " " < 스크립트입니다 src = https://code.jquery.com/jquery-3.3.1.slim.min.js
<ul id="list" class="grid">
<li data-id="id-40" class="win">
<a id="ctl00_cphBody_ListView1_ctrl0_SelectButton" class="project" href="#">
<img src="themes/clean/images/win.jpg" class="project-image" alt="get data-id" />
</a>
</li>
</ul>
끝 - < 스니핏 >;!
컨텐트에서 데이터 id 얻기 위해 '속성' (주로 '< 데이터 id 123";;;; a = " > link< /a>') 사용할 수 있습니다.
$(this).attr("data-id") // will return the string "123"
또는 '.data ()' (jQuery 를 사용하는 경우, 새로운 > 1.4.3 =)
$(this).data("id") // will return the number 123
우리가 원하는 경우 기존 넷윈을 , 또는 업데이트하려면 읽어들이려면 사용하여 이러한 속성 및 메서드 게타트리부트 스테트리부트 JavaScript 를 사용하여 다음과 같이, 그럼 우린 그렇게 할 수 있다
<div id='strawberry-plant' data-fruit='12'></div>
<script>
// 'Getting' data-attributes using getAttribute
var plant = document.getElementById('strawberry-plant');
var fruitCount = plant.getAttribute('data-fruit'); // fruitCount = '12'
// 'Setting' data-attributes using setAttribute
plant.setAttribute('data-fruit','7'); // Pesky birds
</script>
// Fetching data
var fruitCount = $(this).data('fruit');
OR
// If you updated the value, you will need to use below code to fetch new value
// otherwise above gives the old value which is intially set.
// And also above does not work in ***Firefox***, so use below code to fetch value
var fruitCount = $(this).attr('data-fruit');
// Assigning data
$(this).attr('data-fruit','7');
중요. , 특성 있는 점을 유념하십시오 조정할 경우 '' 데이터 무중단으로 javascript 를 통해 데이터 () 는 '이 반영되지 않습니다' 기능을 포함한다. '데이터 ()' 기능을 통해 이를 조정하십시오 합니다 잘 알려져 있다.
<a data-id="123">link</a>
js:
$(this).data("id") // returns 123
$(this).attr("data-id", "321"); //change the attribute
$(this).data("id") // STILL returns 123!!!
$(this).data("id", "321")
$(this).data("id") // NOW we have 321
기존 IE 브라우저에 대한 고민이 있지 않다면, HTML5 데이터세트를 apiu 을 사용할 수도 있습니다.
<div id="my-div" data-info="some info here" data-other-info="more info here">My Awesome Div</div>
var myDiv = document.querySelector('#my-div');
myDiv.dataset.info // "some info here"
myDiv.dataset.otherInfo // "more info here"
데모: http://html5demos.com/dataset
전체 브라우저 지원 목록: [http://caniuse.com/ # 성과 = 데이터세트를] [3]
[3]: http://caniuse.com/ # 성과 = 데이터세트를
아무도 놀라게 한 것.
<select id="selectVehicle">
<option value="1" data-year="2011">Mazda</option>
<option value="2" data-year="2015">Honda</option>
<option value="3" data-year="2008">Mercedes</option>
<option value="4" data-year="2005">Toyota</option>
</select>
$("#selectVehicle").change(function () {
alert($(this).find(':selected').data("year"));
});
다음은 apc® 예:
내가 달러 를 사용하는 .data - http://api.jquery.com/jquery.data/
//Set value 7 to data-id
$.data(this, 'id', 7);
//Get value from data-id
alert( $(this).data("id") ); // => outputs 7
'Id' 는 비트 데이터 액세스 색상에는 고유한 특성을 쉽게 for me.
$ (", # Id") ',' .data (attribute" ";)
<! - begin 스니핏: js 숨기십시오: 거짓값 콘솔: 진정한 바벨. > 거짓값 -;
function myFunction(){
alert($("#button1").data("sample-id"));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" id="button1" data-sample-id="gotcha!" onclick="myFunction()"> Clickhere </button>
끝 - < 스니핏 >;!
이 코드를 데이터 속성 값을 반환되므로 예: , 저는 표시됩니까 id 에 데이터 id 데이터 시간 데이터 이름 상술합니다.
<a href="#" id="click-demo" data-id="a1">Click</a>
js:
$(this).data("id");
// 내려받습니다 값을 > 데이터 id -; a1
$(this).data("id", "a2");
이렇게 하면, - > 데이터 id 변경하십시오 // a2
$(this).data("id");
// 내려받습니다 값을 > 데이터 id -; a2
하는 사람들을 위해 동적으로 사용할 수 있습니다 '폐기' 와 '활성화하십시오 제거하고 재설정하려는 도구팁' 방법입니다. 참조 [https://getbootstrap.com/docs/4.0/components/tooltips/ # 토올팁디스포세] [1]
[1]: https://getbootstrap.com/docs/4.0/components/tooltips/ # 토올팁디스포세