简体   繁体   English

基于当前的innerhtml创建动态jquery变量名

[英]create dynamic jquery variable name based off current innerhtml

Say, I have a div element named something like:说,我有一个名为的 div 元素,如下所示:

<div class="mysterywatch"> {{mysterywatch.righthereiswatch}} </div>

I would simply like to have a dynamic variable based off of the dynamic inner html content inside element ' .mysterywatch ' , so if the below is the current output / contents of .mysterywatch div element... eg.我只想拥有一个基于元素 ' .mysterywatch ' 内动态内部html内容的动态变量,所以如果下面是.mysterywatch div 元素的当前输出/内容......例如。

<h3 class="mysterywatch">Watch1</h3>

..the jQuery variable associated with $('.mysterywatch') would be / update to $Watch1 ..与$('.mysterywatch')关联的 jQuery 变量将 / 更新为$Watch1

var = $Watch1

(All HTML / text that would populate in .mysterywatch would be valid variable syntax. This will be added to frontend validation) (将在.mysterywatch填充的所有 HTML/文本都是有效的变量语法。这将被添加到前端验证中)

Not sure how/why you would want a dynamic variable based off of the inner text of a dynamic piece of content, but here you go:不知道您如何/为什么需要基于动态内容的内部文本的动态变量,但您可以这样做:

var _varname = $('.giantmysterbeer').text();
window[_varname] = 123;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM