'$ (' Meta [name = "csrf-token ']') qanday bajarish mumkin? Javascriptdagi vanilla (attributiv)

Menda jQuery yo'q va men qanday qilib vanilya JavaScript bilan bir narsani qilishim mumkinligini bilishni istayman. Har qanday yordam?

$('meta[name="csrf-token"]').attr('content')
2
jQuery vanilla JavaScript emas;)
qo'shib qo'ydi muallif gtournie, manba
jQuery - bu JavaScript.
qo'shib qo'ydi muallif Fabian Klötzl, manba
jQuery - bu JavaScript.
qo'shib qo'ydi muallif Fabian Klötzl, manba

6 javoblar

document.querySelector('meta[name="csrf-token"]').getAttribute('content');

Siz shunday qilasiz.

6
qo'shib qo'ydi

You can also use getElementsByName

document.getElementsByName ("csrf-token") [0] .getAttribute ("kontent")

4
qo'shib qo'ydi

You can also use getElementsByName

document.getElementsByName ("csrf-token") [0] .getAttribute ("kontent")

4
qo'shib qo'ydi

querySelector() dan foydalaning. > Elementni olish va undan foydalanish uchun getAttribute() usulidan foydalaning.

document.querySelector('meta[name="csrf-token"]').getAttribute('content') 
3
qo'shib qo'ydi

meta elements actually have a content property, so you can simply write:

document.querySelector('meta[name=csrf-token]').content

Namoyish:

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

console.log(
  document.querySelector('meta[name=csrf-token]').content
)
<meta name="csrf-token" content="example-content"/>
</div> </div>
3
qo'shib qo'ydi

meta elements actually have a content property, so you can simply write:

document.querySelector('meta[name=csrf-token]').content

Namoyish:

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

console.log(
  document.querySelector('meta[name=csrf-token]').content
)
<meta name="csrf-token" content="example-content"/>
</div> </div>
3
qo'shib qo'ydi
Javascript UZB
Javascript UZB
99 ishtirokchilar

@js_uzb @vuejs_uz @react_uz @nodejs_uz @angular_uz @ngTashkent @yiiframework_uz @laravel_uz @linux_uzbek @python_uz @swift_uzb —————— @uzdevgroup @UzGeeksGroup ——— @UzDev_Jobs @jobs_uzb