标签: replacewith

使用replaceWith后,.click停止工作

好吧,我现在已经坚持了一段时间......

基本上我有两种方式我想要显示某个div.我计划使用replaceWith()替换#mainDiv与另一个版本的#mainDiv来创建一个函数.

这是功能:

function switchToChoice(){
            $('#myCanvas2').replaceWith('<div id="yesBox" width="150" height="90"><img id="yes" src="Yes-Button.png" width="110" height="55"></div><div id="noBox" width="150" height="90"><img id="no" class src="No-Button.png" width="110" height="55"></div>');

        }
Run Code Online (Sandbox Code Playgroud)

这可以工作并在调用时创建我想要的div框.div框中有两个图像,可以单击,但不执行单击操作.

这是在replaceWith之后无效的代码片段:

//If the user presses the Next button on the comment pages.
        $('#next').click(function() {
            $('#next').fadeTo(100, 0.25, function(){
                clearCanvas(ctx, c);
                wrapText(ctx, questionList[textPos], x, y-20, 275, 15);
                textPos++;
            });
            switchToChoice();
            $('#next').fadeTo(100, 1);
        });

        //If the user presses the Yes button on the question pages.
        $('#yes').click(function() {
            alert("boobs");
            $('#yes').fadeTo(100, 0.25, function(){
                clearCanvas(ctx, c);
                wrapText(ctx, questionList[textPos], x, y-20, 275, 15);
                textPos++; …
Run Code Online (Sandbox Code Playgroud)

html jquery html5 replacewith

2
推荐指数
1
解决办法
1700
查看次数

jQuery noob :(这).replacewith am我做错了吗?

我一直在学习越来越多的jQuery,但在这里我已经陷入困境.

我有一个代码来改变复选框cliked时div的颜色,这很好.

在此之后,我希望能够在焦点上更改textarea的内容,我试过这个:

    //textarea
    $("textarea").focus(function(){
        if ($(this).contains('Skriv valg av headset her')){
         $(this).replaceWith('');
    });  
Run Code Online (Sandbox Code Playgroud)

但是没有效果.我是否有一些语法错误,或者我采取了错误的方法?

这里是jsFiddle的例子.

html jquery replacewith

1
推荐指数
1
解决办法
570
查看次数

在JQuery中使用fadeOut()和fadeIn()替换whileWith()

我想要做的就是简单地淡出容器内的所有图像,将#next1的图像替换为#active,之后再将所有图像淡化.

这是我的代码:

$('.logo').fadeOut('slow', function() {
    $('#active>img').replaceWith( $('#next1>img') );
}).fadeIn('slow', function() {});
Run Code Online (Sandbox Code Playgroud)

这不起作用.我发现自己看着空的#active

但是这个;

$('.logo').fadeOut('slow', function() {}).fadeIn('slow', function() {});
$('#active>img').replaceWith( $('#next1>img') );
Run Code Online (Sandbox Code Playgroud)

使替换很好,但不是我想要做的动画.

我用chrome和ie得到相同的结果.

javascript jquery fadein replacewith jquery-animate

1
推荐指数
1
解决办法
2855
查看次数

我想延迟 jQuery ajax 成功的功能

我想让用户等待 2 秒,然后块内的 HTML 发生变化。你能帮我设置一些时间,这样ajax请求不会那么快,我有时间显示一些动画

我尝试设置超时但不起作用

jQuery(document).ready( function($) {

$(document).on('click', '#wp-request', function(event){
	            event.preventDefault();	
            	var path = myScript.pluginsUrl + '/simple/widget-final.php';
				$.ajax({
					 type : 'POST',
                                         url: path,
                                         cache: false,
					 success : function(data){
					 var newWidget = $(data); 
					 $('#widget-container').replaceWith(newWidget);
					 },
					 error : function(){ alert('Error'); },
					 dataType : 'html'
                });
				
});

$(document).on('click', '#wp-back', function(event){
				event.preventDefault();
				var path = myScript.pluginsUrl + '/simple/widget-initial.php';
				$.ajax({
					 type : 'POST',
                                         url: path,
                                         cache: false,
					 success : function(data){
					 var newWidget = $(data); 
					 $('#widget-container').replaceWith(newWidget);
					 },
					 error : function(){ alert('Error'); },
					 dataType : …
Run Code Online (Sandbox Code Playgroud)

ajax jquery delay replacewith

1
推荐指数
1
解决办法
9767
查看次数

JQuery替换.click()中的$(this)导致无法点击的东西?

我有以下代码:

$('div[class^=locked_]').click(function() {
        var newThis = $(this) ;
        $(this).load(url + " #" + $(this).attr("id"), function() {
            var loaded = $(this).children("#" + $(this).attr("id")) ;
            alert($(loaded).attr("class")) ; // displays "locked_true"
            $(newThis).replaceWith($(loaded)) ;
            alert($(newThis).html()) ;

        }) ;
    }) ;
Run Code Online (Sandbox Code Playgroud)

我不明白我得到的行为:第一个警告显示正确的类(以"locked_"开头).第二个警报显示为null.我不能再次点击相同的按钮,虽然它有合适的类.这是正常的吗?我该怎么办 ?

jquery click this replacewith

0
推荐指数
1
解决办法
137
查看次数

jQuery`replaceWith();`我们可以用外部文件用php替换div(不加载)吗?

我可以<div>用外部PHP脚本替换.像这样的东西:

$('#aside').replaceWith('blocks/filename.php');

请温柔我刚开始学习JavaScript.

更新:

我想替换它<div id="aside">.我想完全删除它并将新内容放在那里.

javascript php jquery replacewith

0
推荐指数
1
解决办法
1666
查看次数

使用.replaceWith更改dom

我有一些代码几乎完全符合我的要求.它将所有强大的标签更改为样式的h3标签,这是完美的,但对于我的生活,我无法弄清楚要替换".click"以使其自动运行.我试过".ready",它在我的jquery中给了我一个错误.

$(document).ready(function(){
    $('strong').click(function(){
        $(this).replaceWith($('<h3 style="margin:0px;display:inline;">' + this.innerHTML + '</h3>'))
    })
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery replacewith

0
推荐指数
1
解决办法
2768
查看次数

如何在swift 3.0中替换@ with*之前的电子邮件ID文本

您好我没有得到完美的解决方案,如何在@with*之前替换电子邮件ID文本

假设我的电子邮件ID是XXXXXXX@gmail.com我想要的输出*******@gmail.com

我试着这样

    let delimiter = "@"
    let newstr = "Himmoradiya@gmail.com"
    var token = newstr.components(separatedBy: delimiter)

    let newQuery = (token[0] as NSString).replacingCharacters(
        in: NSMakeRange(0,token[0].characters.count), with: "*")
Run Code Online (Sandbox Code Playgroud)

任何建议都被接受.

谢谢.

string email ios replacewith swift3

0
推荐指数
1
解决办法
889
查看次数

如何通过AJAX调用的成功回调替换页面的整个HTML或其正文内容?

我需要替换页面的整个HTML或其正文内容(而不是将更多html附加到现有内容).

接受答案在这里教我如何返回数据,但加入到"身体"不相当的工作.这是我现在拥有的jQuery:

<script>
    $(document).ready(function () {
        $("#btnGetData").click(function () {
            document.body.style.cursor = 'wait';
            $.ajax({
                type: 'GET',
                url: '@Url.RouteUrl(routeName : "QuadrantData", routeValues : new { httpRoute = true , unit = "ABUELOS", begdate = "2016-08-20", enddate = "2016-08-27"  })',
                contentType: 'text/plain',
                cache: false,
                xhrFields: {
                    withCredentials: false
                },
                success: function (returneddata) {
                    $("body").remove;
                    $("body").append($(returneddata));
                },
                error: function () {
                    console.log('hey, boo-boo!');
                }
            }); // ajax
            document.body.style.cursor = 'pointer';
        }); // button click
    }); // ready
</script>
Run Code Online (Sandbox Code Playgroud)

...所以你可以看到我试图先删除正文中的html,然后将返回的数据附加到正文中.

这个REST方法返回我想要的html: …

javascript jquery replaceall replacewith asp.net-web-api

-1
推荐指数
1
解决办法
877
查看次数

用python3中的特定元素替换元素组

我有一个超过50个元素的列表.这些元素是小写和大写字母,数字,特殊字符.

例如.

sample_list = ['1', '0', 'b', 'B', '2', '6', 'a', '7', '9', '5', 'c', 'd', '4', 'A', 'C', 'f', 'D', 'F', '3', 'C', '8', 'A', 'F', 'B', 'A', 'A', 'D'] 
Run Code Online (Sandbox Code Playgroud)

我想用特殊字符交换特定元素.例如.

replacing `A,B,C and 1 with @
replacing `D,E,F and 2 with &
replacing `G,H,I and 3 with (
Run Code Online (Sandbox Code Playgroud)

等等,我必须用11个选定的特殊字符替换一组特定的元素.就像我用3个特殊字符替换了几个选中的元素.

如何有效地做到这一点.

python list replacewith python-3.x

-1
推荐指数
1
解决办法
73
查看次数