HTML tagida qiymat olish uchun jQuery'dan foydalaning

Menda quyidagi HTML mavjud:

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

<div class="dragCell ui-draggable ui-draggable-handle" id="thirdSlot">
  <input class="appointmentClassId" type="hidden" value="0013E00000DKsxpQAD">
  <input class="appContactClassId" type="hidden" value="0033E00000AeYkQQAV">
  
Westbrook Restaurants


Z1

<input class="inputHidden-1" name="hiddenName" type="hidden" value="a1M3E0000009rHRUAY"> </div>
</div> </div>

I would like to use access the title attribute in the . i.e 10 AM. How could I do this?

3
JS kodi qayerda? Qaysi hodisani amalga oshirishga harakat qilyapsiz? Va qaysi elementda?
qo'shib qo'ydi muallif Rory McCrossan, manba
@RoryMcCrossan sizning JS kodingizni qo'yish kerakligini aytgan. Oddiy javob uchun foydalanuvchining $ ('span') deb ayta olaman. Attr ('title')
qo'shib qo'ydi muallif Yo Yo, manba
@RoryMcCrossan sizning JS kodingizni qo'yish kerakligini aytgan. Oddiy javob uchun foydalanuvchining $ ('span') deb ayta olaman. Attr ('title')
qo'shib qo'ydi muallif Yo Yo, manba

13 javoblar

Juda oddiy, jQuery attr() dan foydalaning: -

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

console.log($('span').attr('title'));

console.log($('#thirdSlot > p:eq(1)').text());

console.log($('#thirdSlot > p:eq(1)').html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dragCell ui-draggable ui-draggable-handle" id="thirdSlot">
  <input class="appointmentClassId" type="hidden" value="0013E00000DKsxpQAD">
  <input class="appContactClassId" type="hidden" value="0033E00000AeYkQQAV">
  
Westbrook Restaurants


Z1

<input class="inputHidden-1" name="hiddenName" type="hidden" value="a1M3E0000009rHRUAY"> </div>
</div> </div>

Eslatma: - jQuery kutubxonasi kerak. Buni kodingizda yuqoridagi misolga qo'shing. Rahmat

2
qo'shib qo'ydi
Javobni yana bir marta tekshirib ko'ring. Men bu qismni ham qo'shib qo'ydim
qo'shib qo'ydi muallif Alive to Die, manba
Ikkinchi

​​qiymatini qanday qilib olsam bo'ladi? Men nth: child (3) ni sinab ko'rdim

qo'shib qo'ydi muallif saint, manba
bu holatda nima id dinamik ravishda olishni istayman. masalan, bosish faoliyati #secondSlot-da bo'lishi mumkin. Men tanlagan div ni, keyin esa p: eq (1) ni olishni istayman). Qanday qilib buni qila olaman?
qo'shib qo'ydi muallif saint, manba
Hechqisi yo'q. (): $ j (bu) .find ('p: eq (1)')
qo'shib qo'ydi muallif saint, manba

Juda oddiy, jQuery attr() dan foydalaning: -

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

console.log($('span').attr('title'));

console.log($('#thirdSlot > p:eq(1)').text());

console.log($('#thirdSlot > p:eq(1)').html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dragCell ui-draggable ui-draggable-handle" id="thirdSlot">
  <input class="appointmentClassId" type="hidden" value="0013E00000DKsxpQAD">
  <input class="appContactClassId" type="hidden" value="0033E00000AeYkQQAV">
  
Westbrook Restaurants


Z1

<input class="inputHidden-1" name="hiddenName" type="hidden" value="a1M3E0000009rHRUAY"> </div>
</div> </div>

Eslatma: - jQuery kutubxonasi kerak. Buni kodingizda yuqoridagi misolga qo'shing. Rahmat

2
qo'shib qo'ydi
Javobni yana bir marta tekshirib ko'ring. Men bu qismni ham qo'shib qo'ydim
qo'shib qo'ydi muallif Alive to Die, manba
Ikkinchi

​​qiymatini qanday qilib olsam bo'ladi? Men nth: child (3) ni sinab ko'rdim

qo'shib qo'ydi muallif saint, manba
bu holatda nima id dinamik ravishda olishni istayman. masalan, bosish faoliyati #secondSlot-da bo'lishi mumkin. Men tanlagan div ni, keyin esa p: eq (1) ni olishni istayman). Qanday qilib buni qila olaman?
qo'shib qo'ydi muallif saint, manba
Hechqisi yo'q. (): $ j (bu) .find ('p: eq (1)')
qo'shib qo'ydi muallif saint, manba
var x = document.getElementsByTagName("span")[0].getAttribute("title");

Endi x "10" bo'ladi

2
qo'shib qo'ydi
var x = document.getElementsByTagName("span")[0].getAttribute("title");

Endi x "10" bo'ladi

2
qo'shib qo'ydi

Spaningizga classname qo'shing va keyin ushbu kodni ishlating:

$('span.className').attr('title','New Title');​
1
qo'shib qo'ydi
U qanchalik qimmatini olishni xohlasa, siz yangi qiymat o'rnatishga harakat qilyapsiz
qo'shib qo'ydi muallif Carsten Løvbo Andersen, manba

Spaningizga classname qo'shing va keyin ushbu kodni ishlating:

$('span.className').attr('title','New Title');​
1
qo'shib qo'ydi
U qanchalik qimmatini olishni xohlasa, siz yangi qiymat o'rnatishga harakat qilyapsiz
qo'shib qo'ydi muallif Carsten Løvbo Andersen, manba

Span tegingizni identifikatorini ko'rsating


JQuery kodidan foydalaning:

var v=$('#spanid').attr('title');
1
qo'shib qo'ydi

Span tegingizni identifikatorini ko'rsating


JQuery kodidan foydalaning:

var v=$('#spanid').attr('title');
1
qo'shib qo'ydi

.attr('attributename') function is Use to get attribute value of Tag.

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dragCell ui-draggable ui-draggable-handle" id="thirdSlot">
  <input class="appointmentClassId" type="hidden" value="0013E00000DKsxpQAD">
  <input class="appContactClassId" type="hidden" value="0033E00000AeYkQQAV">
  
Westbrook Restaurants


Z1

<input class="inputHidden-1" name="hiddenName" type="hidden" value="a1M3E0000009rHRUAY"> </div> <button onclick="console.log($('span').attr('title'))" >Get Value</button>
</div> </div>
1
qo'shib qo'ydi

.attr('attributename') function is Use to get attribute value of Tag.

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dragCell ui-draggable ui-draggable-handle" id="thirdSlot">
  <input class="appointmentClassId" type="hidden" value="0013E00000DKsxpQAD">
  <input class="appContactClassId" type="hidden" value="0033E00000AeYkQQAV">
  
Westbrook Restaurants


Z1

<input class="inputHidden-1" name="hiddenName" type="hidden" value="a1M3E0000009rHRUAY"> </div> <button onclick="console.log($('span').attr('title'))" >Get Value</button>
</div> </div>
1
qo'shib qo'ydi

Spamga id = "titleSpan" qo'shib qo'ydim va uni sarlavhasi xususiyatiga onload funktsiyasiga kirish uchun jQuery foydalangan. Quyidagi parchani ko'rib chiqing:

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<div class="dragCell ui-draggable ui-draggable-handle" id="thirdSlot">
  <input class="appointmentClassId" type="hidden" value="0013E00000DKsxpQAD">
  <input class="appContactClassId" type="hidden" value="0033E00000AeYkQQAV">
  
Westbrook Restaurants


Z1

<input class="inputHidden-1" name="hiddenName" type="hidden" value="a1M3E0000009rHRUAY"> </div> <script> $(function(){ var spanTitle = $("#titleSpan").attr("title"); console.log(spanTitle); }); </script>
</div> </div>

Umid qilamanki bu yordam.

1
qo'shib qo'ydi
console.log($('span[id="[your id]"]').attr("title"));

yoki

console.log($('span.' + [your className] + ']').attr("title"));

yoki

console.log($('#thirdSlot').find('span').attr('title'));
1
qo'shib qo'ydi
console.log($('span[id="[your id]"]').attr("title"));

yoki

console.log($('span.' + [your className] + ']').attr("title"));

yoki

console.log($('#thirdSlot').find('span').attr('title'));
1
qo'shib qo'ydi