好吧,我现在已经坚持了一段时间......
基本上我有两种方式我想要显示某个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) 我一直在学习越来越多的jQuery,但在这里我已经陷入困境.
我有一个代码来改变复选框cliked时div的颜色,这很好.
在此之后,我希望能够在焦点上更改textarea的内容,我试过这个:
//textarea
$("textarea").focus(function(){
if ($(this).contains('Skriv valg av headset her')){
$(this).replaceWith('');
});
Run Code Online (Sandbox Code Playgroud)
但是没有效果.我是否有一些语法错误,或者我采取了错误的方法?
我想要做的就是简单地淡出容器内的所有图像,将#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得到相同的结果.
我想让用户等待 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)我有以下代码:
$('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.我不能再次点击相同的按钮,虽然它有合适的类.这是正常的吗?我该怎么办 ?
我可以<div>用外部PHP脚本替换.像这样的东西:
$('#aside').replaceWith('blocks/filename.php');
请温柔我刚开始学习JavaScript.
更新:
我想替换它<div id="aside">.我想完全删除它并将新内容放在那里.
我有一些代码几乎完全符合我的要求.它将所有强大的标签更改为样式的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) 您好我没有得到完美的解决方案,如何在@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)
任何建议都被接受.
谢谢.
我需要替换页面的整个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: …
我有一个超过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个特殊字符替换了几个选中的元素.
如何有效地做到这一点.
replacewith ×10
jquery ×8
javascript ×4
html ×2
ajax ×1
click ×1
delay ×1
email ×1
fadein ×1
html5 ×1
ios ×1
list ×1
php ×1
python ×1
python-3.x ×1
replaceall ×1
string ×1
swift3 ×1
this ×1