我有一个html文件,我加载通过DOMDocument
其中我做一些DOM操作输出html与saveHTML
.
问题是删除了输入标签后的空格,这里是HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="/style.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
window.jQuery || document.write(unescape('%3cscript src="/script/jquery.min.js"%3e%3c/script%3e'));
</script>
</head>
<body>
<div>
<div>
<form method="post" action="/register/">
<label>First name: <input type="text" name="firstname"></label>
<label>Last name: <input type="text" name="lastname"></label>
<label>Date of birth: <input type="date" name="dateofbirth"></label>
<label>Address: <input type="text" name="address"></label>
<label>Phone number: <input type="text" name="phonenumber"></label>
<label>Sex: <input type="text" name="sex"></label>
<label>Email address: <input type="email" name="email"></label>
<label>Account password: <input type="password" name="password"></label>
<input id="register-button" type="submit" value="Register">
<input type="reset" …
Run Code Online (Sandbox Code Playgroud) <div class="Port">
<li class="FieldList"><asp:Label CssClass="label" ID="Label4" runat="server"></asp:Label></li>
<li class="FieldList"><asp:Label CssClass="label" ID="Label19" runat="server"></asp:Label></li>
<li class="FieldList"><asp:Label CssClass="label" ID="Label20" runat="server"></asp:Label></li>
</div>
Run Code Online (Sandbox Code Playgroud)
但是在div内部使用li会显示警告信息-验证(XHTML 1.0过渡版):元素'li'不能嵌套在元素'div'中。请提出任何建议
我试图在它上面应用一个/几个CSS3转换后获得JavaScript中元素的高度.
#transformed{
transform:scale(.5);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,JQuery的outerHeight似乎没有天真地做到这一点.
$('#after').outerHeight(); //not affected by the transformation
Run Code Online (Sandbox Code Playgroud)
听起来很简单,呵呵.我发现很多答案,但都使用jQuery或ProtoType.我想要简单的JavaScript.它不应该那么难,但JavaScript不是我的事; 没有中央文件意味着寻找年龄而不是找到我想要的东西.
请考虑以下HTML代码段:
<div class="central_0"> .. </div>
<div class="central_1"> .. </div>
<div class="central_2"> .. </div>
Run Code Online (Sandbox Code Playgroud)
现在我想使用JavaScript来处理那些DIV.
function processDivElements()
{
// search for relevant DIV classes
var divArray = document.getElementsByClass.regex('/^central_.*$/');
// do stuff with the DIV elements found
foreach (divArray as divElement)
{
divElement.style.background = '#f00';
};
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我翻译成适当的纯 JavaScript吗?我使用的是类,而不是ID.我更喜欢使用正则表达式.
所以我试图在动态生成的页面上实现一些谷歌分析事件跟踪.我会用类似的东西
<script>
$(document).ready(function(){
$("#button1").click(function(){
_gaq.push(['_trackEvent', category, action, opt_label, opt_value, opt_noninteraction)']);
});
$("#button2").click(function(){
_gaq.push(['_trackEvent', category, action, opt_label, opt_value, opt_noninteraction']);
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
我想知道是否有可能使用类似的东西document.title
来从页面的html标题自动生成GA代码的类别部分?所有页面都使用独特的标题,如果在这些页面上跟踪的事件可以作为单独的条目而不仅仅是类别显示在GA中,那将会很棒.
我想记住或获取当前拖动元素的数据。这就是我所做的:
$('.source_element').on('dragstart', function(e){
e.originalEvent.dataTransfer.setData("source", this);
});
$('.destination').on('drop', function(e){
var source = e.originalEvent.dataTransfer.getData('source');
console.log(source);
console.log(source.className);
console.log($(source));
$(this).html($(source).html());
e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
第一个 console.log 显示[object HTMLDivElement]
为字符串,而不是对象,第二个undefined
、第三个抛出错误。
所以我怀疑dataTransfer.setData
只接受字符串形式的数据,不允许对象。如果是这样的话,你如何解决这个问题,我如何在不知道其具体ID的情况下记住哪个元素被拖动?
我有以下内容:
var tags = ["Favorite", "Starred", "High Rated"];
for (var tag in tags) {
console.log(tag);
}
Run Code Online (Sandbox Code Playgroud)
输出是
0
1
2
Run Code Online (Sandbox Code Playgroud)
我想输出:
Favorite
Starred
High Rated
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?谢谢.
将样式属性添加到现有样式属性
我有一个 div 元素:
<div id="permissions" style="clear: both; float: left;">
Run Code Online (Sandbox Code Playgroud)
我想在 onsubmit 事件上设置边框:
<div id="permissions" style="clear: both; float: left; border: 1px #F00 solid; ">
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点:将新的样式属性(边框)附加到现有样式(不读取现有样式)?
我正在用 JavaScript 编写一些我需要使用的东西,querySelectorAll.style
但它总是返回 undefined,但它与querySelector.style
. 我怎样才能让它正常工作,以便我可以设置样式?
document.querySelector("div#tabs" + tabId + "> div.page").style.display = 'none'; //works
document.querySelectorAll("div#tabs" + tabId + "> div.page").style.display = 'none';// doesn't work
Run Code Online (Sandbox Code Playgroud) 我想找到一个MySQL查询,将在某个领域找到不同的值,算上2场(1_user,2_user)该值出现的号码,然后按顺序计数的结果.
示例db
+------+-----------+-----------+ | id | 1_user | 2_user | +------+-----------+-----------+ | 1 | 2 | 1 | | 2 | 3 | 2 | | 3 | 8 | 7 | | 4 | 1 | 8 | | 5 | 2 | 8 | | 6 | 3 | 8 | +------+-----------+-----------+
预期结果
user count ----- ----- 8 4 2 3 3 2 1 2