我正在制作一个简单的插件函数,在单击时将元素的背景颜色变为红色.我添加了如下所示的代码,但无法在点击时获得按钮的背景颜色.有人可以更正代码吗?
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$.fn.red({
red:function(){return this.each(function(){this.style.background=red;})}
});
</script>
</head>
<body>
<button onclick="red()">Red</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我正在从xampp数据库中的表中获取数据.我将所有数据打印在2列中,但不知何故,我在tbody的所有行中最后插入了一个额外的<td> </ td>.有人能告诉我问题是怎么回事?
PHP代码:
if ($result->num_rows > 0) {
// output data of each row
echo "<table class='table table-striped'><thead><tr><th>Name</th><th>Email</th></tr></thead><tbody>";
while($row = $result->fetch_assoc()) {echo "<tr><td>".$row["name"]."</td><td>".$row["email"]."<td></tr>";}
echo "</tbody></table>";
}
Run Code Online (Sandbox Code Playgroud) 我有一个输入框,用户可以在其中输入文本。基于此文本,我的UL列表项应被过滤。例如,在文本框中的“ Ab ”上-只有Abbas和Abid必须显示在UL列表的<li>标记中。
index.html
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="angularScript.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<input type="text" />
<ul><li ng-repeat="x in people">{{x.name}}</li></ul>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
angularScript.js
//1. appDeclaration
var app = angular.module('myApp',[]);
//2. controllers
app.controller('myCtrl',function($scope){
$scope.name = "Peter";
$scope.people = [{"name":"Abbas"},{"name":"Tina"},{"name":"Abid"}];
});
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决一些基于输入文本的过滤器,以便只填充与输入框中的文本匹配的lis吗?
我打算只关注指令控制器的使用.所以,pl回答了我提到的每个指令用法实例所提到的相同错误,在指令中提到的控制器部分中,angular会出现一次.
//module declaration
var app = angular.module('myApp',[]);
//controller declaration
app.controller('myCtrl',function($scope){
$scope.name = "Peter";
});
//app declaration
app.directive('myStudent',function(){
return{
template: "Hi! Dear!! {{name}}<br/>",
controller:function(scope, elem, attr){
console.log("controller");
}
}
});Run Code Online (Sandbox Code Playgroud)
<body ng-app="myApp" ng-controller="myCtrl">
<my-student></my-student>
<my-student></my-student>
<my-student></my-student>
<my-student></my-student>
<my-student></my-student>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular.min.js"></script>
</body> Run Code Online (Sandbox Code Playgroud)
注意:
请注意错误和使用指令控制器.我知道同样可以通过预链接,后链接或编译来完成.
PS:我不明白一些外星天才的投票结果!
我试图访问和打印角度指令中的类名.但是,我没有得到理想的结果.相反,为所有值定义未定义.
//module declaration
var app = angular.module('myApp',[]);
//controller declaration
app.controller('myCtrl',function($scope){
$scope.name = "Peter";
});
//app declaration
app.directive('myStudent',function(){
return{
template: "Hi! Dear!! {{name}}<br/>",
compile:function(elem, attr){
console.log("compile");
return{
pre:function(scope,elem,attr){
console.log("pre"+ this.class) ;
},
post:function(scope,elem,attr){
console.log("post"+ this.class);
}
}
},
}
});Run Code Online (Sandbox Code Playgroud)
<body ng-app="myApp" ng-controller="myCtrl">
<my-student class="one"></my-student>
<my-student class="two"></my-student>
<my-student class="three"></my-student>
<my-student class="four"></my-student>
<my-student class="five"></my-student>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular.min.js"></script>
</body> Run Code Online (Sandbox Code Playgroud)
案例一:(任何一般对象)
Obj1 = {
name: "Jack",
age: 21,
address: {
city: "New York",
street: "Black Street",
house_no: 39
}
}
Run Code Online (Sandbox Code Playgroud)
现在,console.log(Obj1.address)
我将得到:
{
city: "New York",
street: "Black Street",
house_no: 39
}
Run Code Online (Sandbox Code Playgroud)
案例二:Window.document
应用相同的逻辑 - 首先我会做console.log(window),然后console.log(window.document)。但是,现在我没有得到 window.document 的正确结构(我应该得到理想的结构),而是得到了 'dom-structure'(我不应该得到理想的结构)。
现在,有人能告诉我为什么会这样吗?如何在 window.document 而不是 html dom 中获得正确的结构?
控制台日志(窗口);
控制台日志(窗口。文档);
现在,有人可以帮助我理解为什么“window.document”没有提供正确的对象结构的问题——它应该提供什么?
我在数组中获得了一组对象(带有国家和州键以及值)的数据。
现在,我需要以这样的方式格式化数据,我得到一个新数组(以 countryName 作为键,状态列表 - 在数组中作为值)。
我正在尝试这样做,但没有成功。有人可以帮我吗?
var data = [
{
"country": "United States",
"states": [
"Alabama",
"Alaska",
"Arizona",
]
},
{
"country": "Canada",
"states": [
"Ontario",
"Saskatchewan",
"Alberta",
]
},
{
"country": "Australia",
"states": [
"Australian Capital Territory",
"Jervis Bay Territory",
"New South Wales",
"Queensland",
]
}
];
newData = [];
data.map(item => newData.push({item.country: item.states});
console.log(newData);Run Code Online (Sandbox Code Playgroud)
我有以下一组运行代码:
useEffect(() => {
if (field[1].isActive === true) {
handleMore();
}
}, [field[1].text]);
Run Code Online (Sandbox Code Playgroud)
问题是有时Fieldjson 响应中没有出现,因此此代码会显示错误。由于我无法将 useEffect 放入某些条件语句中(根据 React 指南,所有 useEffects 应始终以相同的顺序运行),有什么方法可以在依赖项中添加一些代码,例如[field.length? field[1].text: null]. 我不知道。
有人可以帮忙吗?
<head>
<script src=jquery.js></script>
<script src=bootstrap.js></script>
<script src=angular.js></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>
<link rel=stylesheet type="text/css" href=bootstrap.css />
<link rel=stylesheet type=text/css href=mystyle.css />
<style>
#panel{margin:20px;}
#addNew{margin:10px;}
#pagination{text-align:center;}
span{background:#aaa;width:60px;width:60px;}
</style>
</head>
<body ng-app="myApp">
<div ng-controller=myController>
<div id=panel class="panel panel-primary">
<div class="panel-heading">Hero Selection Bar</div>
<div class="panel-body">
<a href="#/one">Page 1</a>
<a href="#/two">Page 2</a>
<a href="#/three">Page 3</a>
<ng-view > </ng-view>
</div>
</div>
</div>
<script>
var app = angular.module('myApp',['ngRoute']);
app.controller('myController', function( $scope, $routeProvider){
$scope.somedata = "THAT";
});
app.config([$routeProvider],function($routeProvider){
$routeProvider
.when('#/one', {templateUrl:"templates/one.html"})
.when('#/two', {templateUrl:"templates/two.html"})
.when('#/three', {templateUrl:"templates/three.html"})
});
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
我将文件保存在'templates …
这些是必须达到相同结果的两个例子:
例1
<script>
console.log(a);
var a = 10;
console.log(a);
</script>
Run Code Online (Sandbox Code Playgroud)
渲染
<script>
var a = "";
console.log(a); //will result undefined
a = 10;
console.log(a); //will result 10
</script>
Run Code Online (Sandbox Code Playgroud)
结果
undefined
10
Run Code Online (Sandbox Code Playgroud)
例2
<script>
console.log(a);
a = 10;
console.log(a);
</script>
Run Code Online (Sandbox Code Playgroud)
期待渲染
<script>
var a = "";
console.log(a); //should result undefined
a = 10;
console.log(a); //should result 10
</script>
Run Code Online (Sandbox Code Playgroud)
结果
现在,根据场景2中的 JS吊装,如果未声明的变量必须已自动声明到其范围之上,但结果应该是相同的.为什么不呢?概念在哪里失败了?
javascript ×8
angularjs ×4
ecmascript-6 ×2
html ×2
arrays ×1
function ×1
hoisting ×1
jquery ×1
mysql ×1
object ×1
php ×1
plugins ×1
react-hooks ×1
reactjs ×1
routing ×1
scope ×1
use-effect ×1