简体   繁体   English

javascript jquery html-如何将标题属性分配给.class

[英]javascript jquery html - how to assign the title attribute to a .class

I have a div that holds the results that is retrieved by ajax. 我有一个div,它保存由ajax检索的结果。 Depends on the result, the div will be assigned a different css class. 根据结果​​,将为div分配不同的CSS类。 I want to attach the title attribute to the classes so that class 1 will show the title 1, and class 2 will show the title 2. My routine is somewhat complicated, so assigning the attr('title','xxx') each time I switch the class has not been successful. 我想将title属性附加到类上,以便类1将显示标题1,而类2将显示标题2。我的例程有些复杂,因此每次都分配attr('title','xxx')我切换班没有成功。

Is it possible to attach the title to a css class like the pseudo code below? 是否可以将标题附加到css类,如下面的伪代码?

TIA TIA

.class1
{
title: 'class1';

}

.class2
{
title: 'class2';

}

Your explanation is a bit unclear, but you may want to try adding live() to the chain before you call attr(title,xxx) . 您的解释还不清楚,但是您可能需要在调用attr(title,xxx)之前尝试将live()添加到链中。 AJAX requests (asynchronous ones) load data into the DOM after the onReady function executes your script, so whatever selector you are using may be invalid at the time the script executes. 在onReady函数执行脚本之后,AJAX请求(异步请求)将数据加载到DOM中,因此您使用的任何选择器在脚本执行时都可能无效。

No, it isn't. 不,不是。

CSS is designed to describe the presentation of a DOM, not its content (even though it dips a toe into that area with content ). CSS旨在描述DOM的表示形式 ,而不是描述其内容(即使它通过content进入该区域也是如此)。

您将仅需使用attr(title,xxx)即使您的例程很复杂,也可以使用jquery选择器在第1行或第2行中进行操作

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

相关问题 如何将 javascript 变量值分配给 HTML 属性? - How to assign javascript variable value to HTML Attribute? 使用JavaScript / jQuery将HTML实体指定为属性值 - Assign a HTML-entity as an attribute value using JavaScript/jQuery 如何使用JavaScript将CSS类分配给svg元素的标题? - how to assign a css class to title of svg element using javascript? 检查页面标题是否包含在链接属性中,并使用jQuery分配活动类 - Check page title is contained within link attribute and assign active class using jQuery 如何将HTML标题属性添加到jQuery UI日期选择器小部件? - How to add html title attribute to jquery ui date picker widget? 如何使用jQuery将元素标题添加到类属性 - How to add title of element to class attribute using jquery 如何在 append HTML 代码之前将 URL 分配给 src 属性 - How to assign URL to src attribute before append the HTML code in jQuery 如何使用javascript从类中的链接获取标题属性 - How to get title attribute from link within a class with javascript 如何在Javascript(greasemonkey)中按类别和检索标题属性搜索元素 - How to search element by class and retreive title attribute in Javascript (greasemonkey) jQuery / Javascript方法获取当前页面的标题,将其与字符串匹配,将类分配给该特定元素 - jQuery / Javascript method to get title of current page, match it to a stringa, assign class to that specific element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM