我有以下内容:
<span class="label-info">3</span>
Run Code Online (Sandbox Code Playgroud)
我有以下jquery
var replaceit = $(this).closest(':has(.label-info)').find('.label-info').text();
Run Code Online (Sandbox Code Playgroud)
变量的值始终是一个整数,但不总是3:
ie: 1, 2, 3, 4, 5.
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多方法,无法获得改变的价值.我的最新尝试是:
return $(this).closest(':has(.label-info)').html().replace(replaceit, (replaceit - 1));
Run Code Online (Sandbox Code Playgroud)
我的最终结果是从"lable-info"的当前值中减去1,并用这个新结果切换它.因此,基于3的值的新跨度将成为.
<span class="label-info">2</span>
Run Code Online (Sandbox Code Playgroud)
我该如何实现这一目标?
更新代码更清晰
HTML:
<div>
<span class="lable-info">3</span>
</div>
<div>
<a class="accept_friend">accept</a>
</div>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
$(document).on("click", "a.accept_friend", function() {
var checkValue = $(this).closest(':has(.name)').find('.name').text();
var removeit = $(this).closest(':has(.item)').find('.item').fadeOut();
var replaceit = $(this).closest(':has(.label-info)').find('.label-info').text();
$.ajax({
url: '/includes/accept_friend.php',
type: 'post',
data: {checkValue},
success:function(data){
return removeit;
$("a.remove_pending").text(function () {
return ('.label-info').html().replace(replacei, replaceit);
});
}
Run Code Online (Sandbox Code Playgroud)
笔记:
我没有使用id.我正在上课.有多个具有相同名称的类.所以我必须通过最近的电话.
我搜索了无数的页面,试图找到真正有效的答案。我已经尝试过库文件来专门处理警告和错误处理,但即使我抑制所有警告和错误,这最后一个警告仍然显示:
Warning: DOMDocument::loadHTML(): Empty string supplied as input
Run Code Online (Sandbox Code Playgroud)
我的php处理如下。只要用户输入实际的 url,该代码就可以完美运行,但是当用户输入的数据不是 url 时,就会显示上面的警告。
if (isset($_GET[article_url])){
$title = 'contact us';
$str = @file_get_contents($_GET[article_url]);
$test1 = str_word_count(strip_tags(strtolower($str)));
if($test1 === FALSE) { $test = '0'; }
if ($test1 > '550') {
echo '<div><i class="fa fa-check-square-o" style="color:green"></i> This article has '.$test1.' words.';
} else {
echo '<div><i class="fa fa-times-circle-o" style="color:red"></i> This article has '.$test1.' words. You are required to have a minimum of 500 words.</div>';
}
$document = new DOMDocument();
$libxml_previous_state = libxml_use_internal_errors(true);
$document->loadHTML($str);
libxml_use_internal_errors($libxml_previous_state); …Run Code Online (Sandbox Code Playgroud) 我搜索并搜索过,发现没有什么可以解释我需要什么.
我有一个webcript,到处都有几十种形式.无论表单的id,类或操作是什么,我都需要在任何表单上单击提交后禁用提交按钮3秒钟.
我找到了以下代码:
$('#btn').click(function(){
var btn = $(this);
$.post('http://someurl.com',{delay: 3}).complete(function(){
btn.prop('disabled', false);
});
btn.prop('disabled', true);
});
Run Code Online (Sandbox Code Playgroud)
但这要求表单的id为btn,并且似乎要求将表单"发布"到某个页面.
有没有办法在所有形式上实现这一点,无论正在执行的行动如何?因此,如果它是一个注册表单,它会禁用"加入"按钮3秒,如果它是一个评论表单,它在提交评论后同样禁用提交3秒,....基本上无论我想要什么形式或行动单击后禁用提交按钮3秒钟.
这甚至可能吗?
我已经尝试将"#btn"的所有实例更改为"输入",但这似乎不起作用.我真的不擅长这些东西,但似乎在别人的帮助下管理绊脚石.
我的问题与其他问题不重复的原因是因为我特别声明"无论表格的内容,类别或行为是什么".在另一个问题上提出的解决方案没有具体解决这个问题.由于各种原因(其社交网络脚本),添加id,类或类似内容并不是具有数百种表单的webscript的远程可能性.我标记为正确的解决方案是不需要将任何属性添加到html元素的解决方案.
我有一个foreach循环,完美运行没有缺陷.
foreach ($row AS $row) {
echo $row['id'];
}
Run Code Online (Sandbox Code Playgroud)
有时候没有返回任何行.我想要回应'没有行'; 什么时候没有行.问题是如果我尝试做如下的事情:
foreach ($row AS $row) {
if (!isset($row['id'])) {
echo 'there are no rows';
} else {
echo $row['id'];
}
}
Run Code Online (Sandbox Code Playgroud)
它永远不会返回"没有行"的回声.我假设这是因为当没有行时,foreach循环不会运行.问题变成了,当有行时,如果没有行而没有干扰foreach,我怎么回应"没有行".
我也尝试过以下代码:
$row1 = $stmt->fetch();
$row = $stmt->fetchAll();
if (isset($row1['id'])) {
foreach ($row AS $row) {
Run Code Online (Sandbox Code Playgroud)
仍然没有运气
所以期望的结果如下:
When loop runs:
1
2
3
4
When loop doesn't run:
there are no rows
Run Code Online (Sandbox Code Playgroud)