我想通过jQuery显示或隐藏以下div:
HTML:
<div class="image" data-style="bw"><img src="img/bw1.jpg"></div>
<div class="image" data-style="fauna"><img src="img/fauna1.jpg"></div>
<div class="image" data-style="bw"><img src="img/bw2.jpg"></div>
JavaScript:
let images=document.querySelectorAll ("image");
let genre = "bw";
images.dataset.style.genre.show();
为什么我遇到错误images.dataset
是undefined
在这里做错了什么?
答案 0 :(得分:0)
您可以像下面那样使用jQuery attribute selector。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaypointEnemy : MonoBehaviour
{
public float speed = 5f;
private Transform target;
private int wavepointIndex = 0;
private Rigidbody2D rigidBody;
bool points = false;
private void Start()
{
{
int random = (Random.Range(-10, 10));
if (random >= 0)
{
target = Waypoints.waypoints[0];
points = true;
} else {
target = Waypoints2.waypoints2[0];
}
}
}
void Update()
{
Vector2 dir = target.position - transform.position;
transform.Translate(dir.normalized * speed * Time.deltaTime, Space.World);
if (Vector2.Distance(transform.position, target.position) <= 0.4f)
{
GetNextWaypoint();
}
}
void GetNextWaypoint()
{
if (points == false)
{
wavepointIndex++;
target = Waypoints.waypoints[wavepointIndex];
} else
{
wavepointIndex++;
target = Waypoints2.waypoints2[wavepointIndex];
}
}
}