Javascript 如何更改jQuery中的单击选项?
首先,我想声明我对jQuery毫无用处, 因此,我面临的问题是,我不知道如何编码点击 现在要关闭弹出窗口,您需要单击按钮,但我希望当您单击弹出窗口外部时,弹出窗口将关闭,您可以在此处看到弹出窗口(单击三角形,然后单击链接) 以下是脚本:Javascript 如何更改jQuery中的单击选项?,javascript,jquery,themes,tumblr,Javascript,Jquery,Themes,Tumblr,首先,我想声明我对jQuery毫无用处, 因此,我面临的问题是,我不知道如何编码点击 现在要关闭弹出窗口,您需要单击按钮,但我希望当您单击弹出窗口外部时,弹出窗口将关闭,您可以在此处看到弹出窗口(单击三角形,然后单击链接) 以下是脚本: <script> $(document).ready(function() { // //When you click on a link with class of poplight and the href starts with a #
<script>
$(document).ready(function() {
//
//When you click on a link with class of poplight and the href starts with a #
$('a.poplight[href^=#]').click(function() {
var popID = $(this).attr('rel'); //Get Popup Name
var popURL = $(this).attr('href'); //Get Popup href to define size
//Pull Query & Variables from href URL
var query= popURL.split('?');
var dim= query[1].split('&');
var popWidth = dim[0].split('=')[1]; //Gets the first query string value
//Fade in the Popup and add close button
$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="http://i60.tinypic.com/r720j6.png" class="btn_close" alt="close" /></a>');
$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend;
//Define margin for center alignment (vertical horizontal) - we add 80px to the height/width to accomodate for the padding and border width defined in the css
var popMargTop = ($('#' + popID).height() + 90) / 2;
var popMargLeft = ($('#' + popID).width() + 90) / 2;
//Apply Margin to Popup
$('#' + popID).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
//Fade in Background
$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies
return false;
});
//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
$('#fade , .thepopup').fadeOut(function() {
$('#fade, a.close').remove(); //fade them both out
});
return false;
});
});
</script>
$(文档).ready(函数(){
//
//当您单击具有poplight类的链接时,href以#
$('a.poplight[href^=#]')。单击(函数(){
var popID=$(this.attr('rel');//获取弹出窗口名称
var popURL=$(this.attr('href');//获取Popup href以定义大小
//从href URL提取查询变量(&V)
var query=popURL.split(“?”);
var dim=query[1]。拆分('&');
var popWidth=dim[0]。拆分('=')[1];//获取第一个查询字符串值
//淡入弹出窗口并添加关闭按钮
$('#'+popID).fadeIn().css({'width':Number(popWidth)}).prepend('');
$('#'+popID).fadeIn().css({'width':Number(popWidth)}).prepend;
//定义中心对齐的边距(垂直-水平)-我们向高度/宽度添加80px,以适应css中定义的填充和边框宽度
var popMargTop=($('#'+popID).height()+90)/2;
var popMargLeft=($('#'+popID).width()+90)/2;
//将边距应用于弹出窗口
$('#'+popID).css({
“页边距顶部”:-popMargTop,
“左边距”:-popMargLeft
});
//淡入背景
$('body').append(“”);//将淡入淡出层添加到body标记的底部。
$('#fade').css({'filter':'alpha(opacity=80)}).fadeIn();//淡入淡入淡入层-.css({'filter':'alpha(opacity=80)})用于修复淡入透明胶片上的IE错误
返回false;
});
//关闭弹出窗口和淡入层
$('a.close,#fade').live('click',function(){//单击关闭或淡入淡出层时。。。
$('#fade,.thepopup').fadeOut(函数(){
$(“#淡入,a.close”).remove();//将它们淡出
});
返回false;
});
});
我应该修改什么?也许这对你有用。我使用类似的东西,但没有jQuery;) 这是我编辑过的版本。它包括您的代码
<script>
$(document).ready(function () {
//
//When you click on a link with class of poplight and the href starts with a #
$('a.poplight[href^=#]').click(function () {
var popID = $(this).attr('rel'); //Get Popup Name
var popURL = $(this).attr('href'); //Get Popup href to define size
//Pull Query & Variables from href URL
var query = popURL.split('?');
var dim = query[1].split('&');
var popWidth = dim[0].split('=')[1]; //Gets the first query string value
//Fade in the Popup and add close button
$('#' + popID).fadeIn().css({ 'width': Number(popWidth) }).prepend('<a href="#" class="close"><img src="http://i60.tinypic.com/r720j6.png" class="btn_close" alt="close" /></a>');
$('#' + popID).fadeIn().css({ 'width': Number(popWidth) }).prepend;
//Define margin for center alignment (vertical horizontal) - we add 80px to the height/width to accomodate for the padding and border width defined in the css
var popMargTop = ($('#' + popID).height() + 90) / 2;
var popMargLeft = ($('#' + popID).width() + 90) / 2;
//Apply Margin to Popup
$('#' + popID).css({
'margin-top': -popMargTop,
'margin-left': -popMargLeft
});
//Fade in Background
$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
$('#fade').css({ 'filter': 'alpha(opacity=80)' }).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies
// add click listener to hole page
$('html, body').click(closePopup);
return false;
});
//Close Popups and Fade Layer
$('a.close, #fade').live('click', closePopup);
// Prevent the listener for the hole page
$("#popupContainer").click(function (e) {
e.stopPropagation();
});
function closePopup(e) {
$('#fade , .thepopup').fadeOut(function () {
$('#fade, a.close').remove(); //fade them both out
});
$('html, body').unbind('click', closePopup);
return false;
}
});
</script>
$(文档).ready(函数(){
//
//当您单击具有poplight类的链接时,href以#
$('a.poplight[href^=#]')。单击(函数(){
var popID=$(this.attr('rel');//获取弹出窗口名称
var popURL=$(this.attr('href');//获取Popup href以定义大小
//从href URL提取查询变量(&V)
var query=popURL.split(“?”);
var dim=query[1]。拆分('&');
var popWidth=dim[0]。拆分('=')[1];//获取第一个查询字符串值
//淡入弹出窗口并添加关闭按钮
$('#'+popID).fadeIn().css({'width':Number(popWidth)}).prepend('');
$('#'+popID).fadeIn().css({'width':Number(popWidth)}).prepend;
//定义中心对齐的边距(垂直-水平)-我们向高度/宽度添加80px,以适应css中定义的填充和边框宽度
var popMargTop=($('#'+popID).height()+90)/2;
var popMargLeft=($('#'+popID).width()+90)/2;
//将边距应用于弹出窗口
$('#'+popID).css({
“页边距顶部”:-popMargTop,
“左边距”:-popMargLeft
});
//淡入背景
$('body').append(“”);//将淡入淡出层添加到body标记的底部。
$(#fade').css({'filter':'alpha(opacity=80)}).fadeIn();//淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入
//将“单击侦听器”添加到“孔”页面
$('html,body')。单击(关闭弹出窗口);
返回false;
});
//关闭弹出窗口和淡入层
$('a.close,#fade').live('click',closePopup');
//阻止孔页的侦听器
$(“#popupContainer”)。单击(函数(e){
e、 停止传播();
});
功能关闭弹出窗口(e){
$('#淡入,.thepoup')。淡出(函数(){
$(“#淡入,a.close”).remove();//将它们淡出
});
$('html,body')。取消绑定('click',关闭弹出窗口);
返回false;
}
});
检查这是否有帮助。我真的不知道该把它放在哪里,我真的很烂:(
<script>
$(document).ready(function () {
//
//When you click on a link with class of poplight and the href starts with a #
$('a.poplight[href^=#]').click(function () {
var popID = $(this).attr('rel'); //Get Popup Name
var popURL = $(this).attr('href'); //Get Popup href to define size
//Pull Query & Variables from href URL
var query = popURL.split('?');
var dim = query[1].split('&');
var popWidth = dim[0].split('=')[1]; //Gets the first query string value
//Fade in the Popup and add close button
$('#' + popID).fadeIn().css({ 'width': Number(popWidth) }).prepend('<a href="#" class="close"><img src="http://i60.tinypic.com/r720j6.png" class="btn_close" alt="close" /></a>');
$('#' + popID).fadeIn().css({ 'width': Number(popWidth) }).prepend;
//Define margin for center alignment (vertical horizontal) - we add 80px to the height/width to accomodate for the padding and border width defined in the css
var popMargTop = ($('#' + popID).height() + 90) / 2;
var popMargLeft = ($('#' + popID).width() + 90) / 2;
//Apply Margin to Popup
$('#' + popID).css({
'margin-top': -popMargTop,
'margin-left': -popMargLeft
});
//Fade in Background
$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
$('#fade').css({ 'filter': 'alpha(opacity=80)' }).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies
// add click listener to hole page
$('html, body').click(closePopup);
return false;
});
//Close Popups and Fade Layer
$('a.close, #fade').live('click', closePopup);
// Prevent the listener for the hole page
$("#popupContainer").click(function (e) {
e.stopPropagation();
});
function closePopup(e) {
$('#fade , .thepopup').fadeOut(function () {
$('#fade, a.close').remove(); //fade them both out
});
$('html, body').unbind('click', closePopup);
return false;
}
});
</script>