A部分:
我知道有很多东西告诉你浏览器是否支持某个HTML5属性,例如http://diveintohtml5.info/detect.html,但他们没有告诉你如何从个人获取类型元素并使用该信息来初始化您的插件.
所以我尝试过:
alert($("input:date"));
//returns "[object Object]"
alert($("input[type='date']"));
//returns "[object Object]"
alert($("input").attr("type"));
//returns "text" ... which is a lie. it should have been "date"
Run Code Online (Sandbox Code Playgroud)
没有人工作.
我最终想出了这个(确实有效):
var inputAttr = $('<div>').append($(this).clone()).remove().html().toLowerCase();
alert(inputAttr);
// returns "<input min="-365" max="365" type="date">"
Run Code Online (Sandbox Code Playgroud)
谢谢:http://jquery-howto.blogspot.com/2009/02/how-to-get-full-html-string-including.html
所以我的第一个问题:1.为什么我不能在不支持html5的浏览器中读取"type"属性?您可以组成任何其他属性和伪造值并阅读它.2.为什么我的解决方案有效?为什么它在DOM中是否重要?
B部分:
以下是我使用探测器的基本示例:
<script type="text/javascript" >
$(function () {
var tM = document.createElement("input");
tM.setAttribute("type", "date");
if (tM.type == "text") {
alert("No date type support on a browser level. Start adding date, week, month, and time …Run Code Online (Sandbox Code Playgroud) 当我运行此功能时:
onUnCheck: function(el) {
var thenames = "icon-"+el.find("label:first").text().replace(/ /g,'').toLowerCase();
alert(thenames);
$("'."+thenames+"'").hide("fast");
}
Run Code Online (Sandbox Code Playgroud)
我生成一个字符串.我可以在alert()中看到它确实是正确的字符串.例:
icon-jira
Run Code Online (Sandbox Code Playgroud)
但是当我将字符串作为jQuery选择器传递时,它不起作用.
我知道函数的逻辑是合理的,因为粘贴我的alert()的结果使它工作.
为什么jQuery不接受我的字符串?
使用此代码:
<ul class="tabs-nav" role="tablist" >
<li role="tab"><a href="#newspane" id="tab-newnews">Latest News</a></li>
<li role="tab"><a href="#presspane" id="tab-press" >Press Releases</a></li>
</ul>
<div>
<div id="pane-newnews" role="tabpanel" aria-labelledby="tab-newnews" aria-hidden="false">
<p>Lorem</p>
</div>
<div id="pane-press" role="tabpanel" aria-labelledby="tab-press" aria-hidden="true">
<p>Ipsem</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我在W3C验证器上收到此错误:
"元素div上属性角色的错误值列表"
我已经翻过文档中的每一块石头,发现没有理由不能验证.谁能解释我做错了什么?
谢谢!
我正在寻找一个匹配选择器的存在.哪个更快?
$('a[rel="something"]').first().length > 0)
Run Code Online (Sandbox Code Playgroud)
要么
$('a[rel="something"]').length > 0)
Run Code Online (Sandbox Code Playgroud)
谢谢!