jQuery动态创建节点元素
来源:互联网 发布:ai做淘宝照片 编辑:程序博客网 时间:2024/06/10 00:43
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<style type="text/css">
#divLeft
{
float: left;
width: 300px;
height: 400px;
border: 1px solid red;
margin-right: 10px;
}
#divRight
{
float: left;
width: 500px;
height: 600px;
border: 1px solid red;
}
</style>
<script type="text/javascript">
$(function () {
var strAdd = '';
var strAddOption = '';
var strAddOptionValue = '';
$('#txtValue').blur(function () {
if ($(this).val() == '') {
$('#txtValue').val('请输入属性名');
}
else {
var sel2 = $('#Select2 :checked').text();
if (sel2 == 'width') {
strAdd += 'width=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
else if (sel2 == 'height') {
strAdd += 'height=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
else if (sel2 == 'src') {
strAdd += 'src=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
else if (sel2 == 'multiple') {
strAdd += 'multiple=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
else if (sel2 == 'value') {
if ($('#Select1').val() == 'select') {
strAddOptionValue = 'value=' + $('#txtValue').val() + " ";
$('span').text(strAdd + " " + strAddOption + " " + strAddOptionValue);
}
else {
strAdd += 'value=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
}
else if (sel2 == 'class') {
strAdd += 'class=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
else if (sel2 == 'id') {
strAdd += 'id=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
else if (sel2 == 'option') {
strAddOption += '<option ' + strAddOptionValue + ' >' + $('#txtValue').val() + '</option>' + " ";
$('span').text(strAdd + " " + strAddOption);
}
}
})
$('#txtValue').focus(function () {
$('#txtValue').val('');
})
$('#Button1').click(function () {
var YSstr = $('#Select1').val();
if (YSstr == 'img') {
var str = $('<' + YSstr + ' ' + strAdd + '/>');
$('#divRight').append(str);
}
else if (YSstr == 'p') {
var str = $('<' + YSstr + '>' + $('#txtContent').val() + '</' + YSstr + '>');
$('#divRight').append(str);
}
else {
var str = $('<' + YSstr + ' ' + strAdd + '>' + strAddOption + '</' + YSstr + '>');
$('#divRight').append(str);
}
})
})
</script>
</head>
<body>
<div id="divLeft">
元素名:<select id="Select1">
<option value="p">p</option>
<option value="img">img</option>
<option value="select">select</option>
</select>
<br />
<br />
属性:<select id="Select2">
<option value="width">width</option>
<option value="height">height</option>
<option value="src">src</option>
<option value="multiple">multiple</option>
<option value="multiple">value</option>
<option value="src">class</option>
<option value="multiple">id</option>
<option value="multiple">option</option>
</select>
<br />
<br />
属性值:<input id="txtValue" type="text" value="请输入属性值:" />
<br />
<br />
内容:<input id="txtContent" type="text" />
<br />
<br />
<span></span>
<input id="Button1" type="button" value="创建" />
</div>
<div id="divRight">
</div>
</body>
</html>
<head>
<title></title>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<style type="text/css">
#divLeft
{
float: left;
width: 300px;
height: 400px;
border: 1px solid red;
margin-right: 10px;
}
#divRight
{
float: left;
width: 500px;
height: 600px;
border: 1px solid red;
}
</style>
<script type="text/javascript">
$(function () {
var strAdd = '';
var strAddOption = '';
var strAddOptionValue = '';
$('#txtValue').blur(function () {
if ($(this).val() == '') {
$('#txtValue').val('请输入属性名');
}
else {
var sel2 = $('#Select2 :checked').text();
if (sel2 == 'width') {
strAdd += 'width=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
else if (sel2 == 'height') {
strAdd += 'height=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
else if (sel2 == 'src') {
strAdd += 'src=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
else if (sel2 == 'multiple') {
strAdd += 'multiple=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
else if (sel2 == 'value') {
if ($('#Select1').val() == 'select') {
strAddOptionValue = 'value=' + $('#txtValue').val() + " ";
$('span').text(strAdd + " " + strAddOption + " " + strAddOptionValue);
}
else {
strAdd += 'value=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
}
else if (sel2 == 'class') {
strAdd += 'class=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
else if (sel2 == 'id') {
strAdd += 'id=' + $('#txtValue').val() + " ";
$('span').text(strAdd);
}
else if (sel2 == 'option') {
strAddOption += '<option ' + strAddOptionValue + ' >' + $('#txtValue').val() + '</option>' + " ";
$('span').text(strAdd + " " + strAddOption);
}
}
})
$('#txtValue').focus(function () {
$('#txtValue').val('');
})
$('#Button1').click(function () {
var YSstr = $('#Select1').val();
if (YSstr == 'img') {
var str = $('<' + YSstr + ' ' + strAdd + '/>');
$('#divRight').append(str);
}
else if (YSstr == 'p') {
var str = $('<' + YSstr + '>' + $('#txtContent').val() + '</' + YSstr + '>');
$('#divRight').append(str);
}
else {
var str = $('<' + YSstr + ' ' + strAdd + '>' + strAddOption + '</' + YSstr + '>');
$('#divRight').append(str);
}
})
})
</script>
</head>
<body>
<div id="divLeft">
元素名:<select id="Select1">
<option value="p">p</option>
<option value="img">img</option>
<option value="select">select</option>
</select>
<br />
<br />
属性:<select id="Select2">
<option value="width">width</option>
<option value="height">height</option>
<option value="src">src</option>
<option value="multiple">multiple</option>
<option value="multiple">value</option>
<option value="src">class</option>
<option value="multiple">id</option>
<option value="multiple">option</option>
</select>
<br />
<br />
属性值:<input id="txtValue" type="text" value="请输入属性值:" />
<br />
<br />
内容:<input id="txtContent" type="text" />
<br />
<br />
<span></span>
<input id="Button1" type="button" value="创建" />
</div>
<div id="divRight">
</div>
</body>
</html>
- jQuery动态创建节点元素
- jQuery动态创建元素以及追加节点
- jQuery中动态创建元素节点无法触发事件
- jQuery中动态创建元素节点无法触发事件
- jQuery中动态创建元素节点无法触发事件
- jquery 节点操作(动态创建元素/添加元素/清空元素/复制元素)
- jquery 动态创建元素
- jQuery动态创建元素
- jquery 动态创建元素
- jquery 动态创建元素
- jquery动态创建dom节点
- 用jquery动态创建元素
- document对象 动态的创建元素(节点)/添加元素(节点)/删除元素(节点)
- jquery和JavaScript动态创建节点
- javascript和jquery动态创建html元素
- javascript和jquery动态创建html元素
- JQuery动态创建DOM、表单元素
- jQuery获取动态创建元素的内容
- 友元函数
- NYOJ - 阶乘因式分解(二)
- android应用 获取本地指定类型文件 的两种最优方法
- jQuery获取浏览器中的分辨率
- java中取出表单的字段名
- jQuery动态创建节点元素
- 对于我自己来说,看Matlab程序的问题
- Android “再按一次返回键退出程序”实现介绍
- android_加载外部资产文件的几种方案
- CMD常用命令
- Android 开发常用代码片段
- Listening - Listening Primer
- MAP容器的使用
- Android 如何将图片和文字同时分享到微信