我有这些函数来创建元素并更改其属性.你能给我一个如何修改它们的建议吗?
function create(elem) {
return document.createElementNS ? document.createElementNS("http://www.w3.org/1999/ xhtml", elem) : document.createElement(elem);
}
function attr(elem, name, value) {
if (!name || name.constructor != String) return "";
name = {"for": "htmlFor", "class": "className"}[name] || name;
if (typeof value != "undefined") {
elem[name] = value;
if (elem.setAttribute) elem.setAttribute(name, value);
}
return elem[name] || elem.getAttribute(name) || "";
}
Run Code Online (Sandbox Code Playgroud)
我希望得到像这样的东西('div',{'id':'test','class':'smth'});
function create(elem, attr) {
if (!attr) return document.createElementNS ? document.createElementNS("http://www.w3.org/1999/xhtml", elem) : document.createElement(elem);
if (attr) {
var el = document.createElementNS ? document.createElementNS("http://www.w3.org/1999/xhtml", elem) …Run Code Online (Sandbox Code Playgroud) 在不使用图像或javascript的情况下很难设置提交输入.
据我所知,没有办法将HTML代码直接插入到sumbit输入值中.如果我将提交输入包装在div元素中(例如添加多个边框),则不是整个区域都是可点击的.
点击标签会导致在所有浏览器中提交表单吗?
<form method="test.rb">
<input type="text" name="test" id="test" />
<label for="button">
<input type="submit" name="button" id="button" value="Send!" />
</label>
</form>
Run Code Online (Sandbox Code Playgroud) 使用负边距去除包装元素的填充是一个好习惯吗?
例如,以下哪个代码片段更适合使用?
<div style="padding: 5px;">
Shortened width string
<div style="margin: 0 -5px;">Full width string</div>
Shortened width string
</div>
Run Code Online (Sandbox Code Playgroud)
或者
<div>
<div style="padding: 5px;">Shortened width string</div>
<div>Full width string</div>
<div style="padding: 5px;">Shortened width string</div>
</div>
Run Code Online (Sandbox Code Playgroud) 在我的Web应用程序中,我使用几个CSS类来编写更少的代码.我经常在标记中使用它们在某些情况下添加单个属性或两个属性.
这些是以下内容
.clear { float: none; clear: both; }
.fl_l{ float: left; }
.fl_r{ float: right; }
.ta_l{ text-align: left; }
.ta_r{ text-align: right; }
.no_td:hover { text-decoration: none; }
Run Code Online (Sandbox Code Playgroud)
你使用什么类似的课程?你有没有在其他项目中看到这种技术?
请帮我创建一个转换日期的功能
2010-10-04 17:45:50
Run Code Online (Sandbox Code Playgroud)
变成更漂亮的东西
10 October at 17:45
Run Code Online (Sandbox Code Playgroud)
如果它们不是真的需要它可以隐藏数年,并显示日期
today/yesterday at 17:45
Run Code Online (Sandbox Code Playgroud)
这有点类似于Facebook显示过去日期的方式.
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Test Title</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
Run Code Online (Sandbox Code Playgroud)
为什么两个meta标签总是在标题之前,其他之后?
是否有任何原因(兼容性,编码参考或规则)我不能在标题之前放置所有元标记?
css ×2
html ×2
attributes ×1
class ×1
class-design ×1
click ×1
conventions ×1
date ×1
function ×1
javascript ×1
label ×1
labels ×1
margin ×1
margins ×1
onclick ×1
padding ×1
php ×1
reference ×1