网站地图    收藏   

主页 > 前端 > css教程 >

实现动态创建html元素功能 - html/css语言栏目:

来源:自学PHP网    时间:2015-04-14 14:51 作者: 阅读:

[导读] #divLeft{float: left;width: 300px;height: 400px;margin-right: 10px;}#divRight{float: left;width: 500px;height: 600px;border: 1px solid red;}$(function () {var strAdd = #39;#39;;va......

#divLeft
{
float: left;
width: 300px;
height: 400px;
margin-right: 10px;
}
#divRight
{
float: left;
width: 500px;
height: 600px;
border: 1px solid red;
}


$(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 += '' + $('#txtValue').val() + '' + " ";
$('span').text(strAdd + " " + strAddOption);
}
}
})

$('#txtValue').focus(function () {
$('#txtValue').val('');
})


$('#Button1').click(function () {
var YSstr = $('#Select1').val();

if (YSstr == 'img') {
var str = $('');
$('#divRight').append(str);
}
else if (YSstr == 'p') {
var str = $('' + $('#txtContent').val() + '');
$('#divRight').append(str);
}
else {
var str = $('' + strAddOption + '');
$('#divRight').append(str);
}

})

})

 

元素名:pimgselect


属性widthheightsrcmultiplevalueclassidoption


属性值:


 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论