关于jquery取值的问题
时间:2009-05-03
来源:互联网
小弟是刚刚接触jquery,现在找到一个弹出新窗口的代码,但是我想要把新窗口填入的内容取出来,但是很难实现,不知道谁可以指点一下,下面是代码
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<title>Test</title>
<script src=jquery.js type=text/javascript></script>
<script type="text/javascript">
$(document).ready(function(){
$("#oButton").click(function(){
openwin.getWin();
});
});
var openwin = {};
openwin.getWin = function(){
var obj = $("#open");
//是否已经新开窗口
if(obj.html() != "" ){
openWindow = $("#newWindow");//存在窗口
openWindow.slideToggle("slow");//显示效果
}else{
//模拟弹出窗口样式
var openWindow = $(openwin.getHtml());//不存在窗口
//定义CSS样式 模拟关键 自定义设置CSS样式
openWindow.css({
'font-size':'12px',
'position':'absolute',
'margin':'20px',
'left':'50px',
'top':'20px',
'width':'300px',
'background-color':'#f0f5FF',
'border': '1px solid #000',
'z-index': '50',
'padding':'10px'
});
openWindow.appendTo($("#open"));
}
//绑定单击事件 确定
openWindow.find("#show").click(function(){
openwin.showWindow();
}).end();
//绑定单击事件 关闭
openWindow.find("#closed").click(function(){
openwin.closeWindow();
}).end();
}
//获取窗口页面元素 模拟窗口
openwin.getHtml = function(){
//自定义页面元素,样式,大小等
html = '<div id="newWindow">';
html += '<p>jQuery弹出窗口</p>';
html += '<p>网站:<input type="text" name="words" id="words" value="gideon" /></p>';
html += '<p><button id="show">确定</button> <button id="closed">关闭</button></p>';
html += '</div>';
return html;
}
//确认事件
openwin.showWindow = function(){
$("#newWindow").hide();
}
//关闭事件
openwin.closeWindow = function(){
$("#newWindow").hide();
}
</script>
</head>
<body>
<button id="oButton">弹出窗口</button>
<div id="open"></div>
<div id="content"></div>
</body>
</html>
我想取出 id 为 #words 的value, 我尝试了 alert ( $ ( "#words" ).val( ) ),但是就是取不到它的值,如果取不到值的话,这个代码也就没有什么用了,只是看,不经用,有点可惜,请大侠指点!!!
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<title>Test</title>
<script src=jquery.js type=text/javascript></script>
<script type="text/javascript">
$(document).ready(function(){
$("#oButton").click(function(){
openwin.getWin();
});
});
var openwin = {};
openwin.getWin = function(){
var obj = $("#open");
//是否已经新开窗口
if(obj.html() != "" ){
openWindow = $("#newWindow");//存在窗口
openWindow.slideToggle("slow");//显示效果
}else{
//模拟弹出窗口样式
var openWindow = $(openwin.getHtml());//不存在窗口
//定义CSS样式 模拟关键 自定义设置CSS样式
openWindow.css({
'font-size':'12px',
'position':'absolute',
'margin':'20px',
'left':'50px',
'top':'20px',
'width':'300px',
'background-color':'#f0f5FF',
'border': '1px solid #000',
'z-index': '50',
'padding':'10px'
});
openWindow.appendTo($("#open"));
}
//绑定单击事件 确定
openWindow.find("#show").click(function(){
openwin.showWindow();
}).end();
//绑定单击事件 关闭
openWindow.find("#closed").click(function(){
openwin.closeWindow();
}).end();
}
//获取窗口页面元素 模拟窗口
openwin.getHtml = function(){
//自定义页面元素,样式,大小等
html = '<div id="newWindow">';
html += '<p>jQuery弹出窗口</p>';
html += '<p>网站:<input type="text" name="words" id="words" value="gideon" /></p>';
html += '<p><button id="show">确定</button> <button id="closed">关闭</button></p>';
html += '</div>';
return html;
}
//确认事件
openwin.showWindow = function(){
$("#newWindow").hide();
}
//关闭事件
openwin.closeWindow = function(){
$("#newWindow").hide();
}
</script>
</head>
<body>
<button id="oButton">弹出窗口</button>
<div id="open"></div>
<div id="content"></div>
</body>
</html>
我想取出 id 为 #words 的value, 我尝试了 alert ( $ ( "#words" ).val( ) ),但是就是取不到它的值,如果取不到值的话,这个代码也就没有什么用了,只是看,不经用,有点可惜,请大侠指点!!!
作者: gideon300 发布时间: 2009-05-03
有人吗?
作者: gideon300 发布时间: 2009-05-03
周末人是少点,大家都休息了嘛。
话说,你的代码中没有看到哪里取了$ ( "#words" ).val( )
我这里也没法进一步帮你了
话说,你的代码中没有看到哪里取了$ ( "#words" ).val( )
我这里也没法进一步帮你了
作者: shawphy 发布时间: 2009-05-03
我取了,只是没有写上去而已!
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<title>Test</title>
<script src=jquery.js type=text/javascript></script>
<script type="text/javascript">
$(document).ready(function(){
$("#oButton").click(function(){
openwin.getWin();
});
});
var openwin = {};
openwin.getWin = function(){
var obj = $("#open");
//是否已经新开窗口
if(obj.html() != "" ){
openWindow = $("#newWindow");//存在窗口
openWindow.slideToggle("slow");//显示效果
}else{
//模拟弹出窗口样式
var openWindow = $(openwin.getHtml());//不存在窗口
//定义CSS样式 模拟关键 自定义设置CSS样式
openWindow.css({
'font-size':'12px',
'position':'absolute',
'margin':'20px',
'left':'50px',
'top':'20px',
'width':'300px',
'background-color':'#f0f5FF',
'border': '1px solid #000',
'z-index': '50',
'padding':'10px'
});
openWindow.appendTo($("#open"));
}
//绑定单击事件 确定
openWindow.find("#show").click(function(){
openwin.showWindow();
}).end();
//绑定单击事件 关闭
openWindow.find("#closed").click(function(){
openwin.closeWindow();
}).end();
}
//获取窗口页面元素 模拟窗口
openwin.getHtml = function(){
//自定义页面元素,样式,大小等
html = '<div id="newWindow">';
html += '<p>jQuery弹出窗口</p>';
html += '<p>网站:<input type="text" name="words" id="words" value="gideon" /></p>';
html += '<p><button id="show">确定</button> <button id="closed">关闭</button></p>';
html += '</div>';
return html;
}
//确认事件
openwin.showWindow = function(){
$("#newWindow").hide();
$("#content").text( $ ( "#words" ).val( ) )
}
//关闭事件
openwin.closeWindow = function(){
$("#newWindow").hide();
}
</script>
</head>
<body>
<button id="oButton">弹出窗口</button>
<div id="open"></div>
<div id="content"></div>
</body>
</html>
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<title>Test</title>
<script src=jquery.js type=text/javascript></script>
<script type="text/javascript">
$(document).ready(function(){
$("#oButton").click(function(){
openwin.getWin();
});
});
var openwin = {};
openwin.getWin = function(){
var obj = $("#open");
//是否已经新开窗口
if(obj.html() != "" ){
openWindow = $("#newWindow");//存在窗口
openWindow.slideToggle("slow");//显示效果
}else{
//模拟弹出窗口样式
var openWindow = $(openwin.getHtml());//不存在窗口
//定义CSS样式 模拟关键 自定义设置CSS样式
openWindow.css({
'font-size':'12px',
'position':'absolute',
'margin':'20px',
'left':'50px',
'top':'20px',
'width':'300px',
'background-color':'#f0f5FF',
'border': '1px solid #000',
'z-index': '50',
'padding':'10px'
});
openWindow.appendTo($("#open"));
}
//绑定单击事件 确定
openWindow.find("#show").click(function(){
openwin.showWindow();
}).end();
//绑定单击事件 关闭
openWindow.find("#closed").click(function(){
openwin.closeWindow();
}).end();
}
//获取窗口页面元素 模拟窗口
openwin.getHtml = function(){
//自定义页面元素,样式,大小等
html = '<div id="newWindow">';
html += '<p>jQuery弹出窗口</p>';
html += '<p>网站:<input type="text" name="words" id="words" value="gideon" /></p>';
html += '<p><button id="show">确定</button> <button id="closed">关闭</button></p>';
html += '</div>';
return html;
}
//确认事件
openwin.showWindow = function(){
$("#newWindow").hide();
$("#content").text( $ ( "#words" ).val( ) )
}
//关闭事件
openwin.closeWindow = function(){
$("#newWindow").hide();
}
</script>
</head>
<body>
<button id="oButton">弹出窗口</button>
<div id="open"></div>
<div id="content"></div>
</body>
</html>
作者: gideon300 发布时间: 2009-05-06
成功了! 哈哈
作者: gideon300 发布时间: 2009-05-06
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28