我有 10 个段落,每个段落显示一个从 1 到 10 的数字。我需要一个函数,当点击段落时,读取它的描述并将其存储在一个数组中。到目前为止,我设法做到了这一点:
function readValue(p) {
var text = document.getElementsByTagName('p')[0].innerHTML;
console.log(text);
}
Run Code Online (Sandbox Code Playgroud)
但是当我点击第 5 段时,它仍然记录1
到控制台。
如何更改以获取实际单击的段落的内容?
我对这段代码有两个问题.我遇到了麻烦,因为提交按钮事件无法识别在文本框事件中计算的变量,并且因为文本框事件未将我的if语句识别为语句.你可以在下面的评论中看到我遇到麻烦的地方.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication11
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
int points;
int userInput = int.Parse(textBox1.Text);
if (userInput == 0)
{
points == 5; //I CANNOT COMPILE BECAUSE APPARENTLY I AM NOT ALLOWED TO USE
THIS AS A STATEMENT?
}
if (userInput == …
Run Code Online (Sandbox Code Playgroud) 我希望函数mozaic在mouseover时启动并在mouseleave时停止.第一个正常工作.这是代码:
$('#name').mouseover(function() {
var mozaic = setInterval(mosaic, 150);
});
$('#name').mouseout(function() {
//code...
});
function mosaic() {
setTimeout(function() {
$('#name').addClass('shadowLasure');
}, 0);
setTimeout(function() {
$('#name').removeClass('shadowLasure');
$('#name').addClass('shadowPink');
}, 50);
setTimeout(function() {
$('#name').removeClass('shadowPink');
}, 100);
}
Run Code Online (Sandbox Code Playgroud) 有什么区别:
$(document).mousedown( someFunction );
Run Code Online (Sandbox Code Playgroud)
和...
document.addEventListener('mousedown', someFunction, false);
Run Code Online (Sandbox Code Playgroud) events ×4
javascript ×2
jquery ×2
c# ×1
html ×1
if-statement ×1
mouseevent ×1
mouseover ×1
object ×1
onclick ×1
statements ×1