我有一个网站,供客户提供数据库中的信息.但是其他网站想在他们的网站上显示这些信息,所以我的客户问我这个.
从一开始我就认为它可能类似于twitter小部件.因为我想给出类似于此的代码:
<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({ ......
Run Code Online (Sandbox Code Playgroud)
其他网站将显示我的数据库中的信息.
但我找不到一个确切的例子,我发现了这个:http://tutorialzine.com/2010/03/who-is-online-widget-php-mysql-jquery/
但这并不是我想要的.
我的部署如下:在服务器中我有一个mySQL数据库和一个网站,我想创建php和javascript代码(甚至jquery,但我不是很专业)所以其他网站可以合并来自数据库的安全模式的信息.
任何人都可以暗示一下吗?
我对Jquery中的.click函数有疑问.我有这个代码:
for (var i = 0; i < 5; i++) {
var divTest = $('<div></div>');
divTest.text("My Div " + i);
divTest.click(function() {
alert("Alert: Div " + i);
});
$('#myTest').append(divTest);
}?
Run Code Online (Sandbox Code Playgroud)
我希望在"myTest"元素中添加5个div,对于每个div,onclick函数会显示带有相应div编号的警报.
正确添加了div,但是当我点击div时,我总是得到带有文本的警报:"Alert: Div 5".为什么?我需要改变什么才能产生我期待的行为?
这是我的jsFiddle:http://jsfiddle.net/BKFGm/2/
我在formcomponent类中有一个数组,并希望能够将该数组传递给验证器函数.在表单中添加多个验证器时,我使用的是Validators.compose函数.这只接受验证器函数的名称,而不接受任何要传递的参数.是否可以在"compose"函数内的函数调用中添加参数?
export class ClientFormComponent
{
clientForm: ControlGroup;
npi: AbstractControl;
name: AbstractControl;
constructor(private _clientService: ClientService, _fb: FormBuilder) {
this.clientForm = _fb.group({ 'name': ['', Validators.compose([Validators.required])], 'npi': ['', Validators.compose([Validators.required, npiNumValidator, Validators.maxLength(10), Validators.minLength(10)])]});
this.name = this.clientForm.controls['name'];
this.npi = this.clientForm.controls['npi'];
}
@Input() clientList;
active = true;
onSubmit(value: Client) {
this._clientService.addDeleteClient(value, true)
.subscribe(
client => this.clientList.push(client));
}
}
function npiNumValidator(control: Control): { [s: string]: boolean } {
if (isNaN(control.value)) {
return { npiNAN: true };
}
}Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我正在尝试使用网络爬虫来从某些网站获取产品以减少我的内存使用量(我在某处找不到内存泄漏).所以我试图异步地向一个回调发送参数,以便终止当前的上下文.
这就是我所在的地方:
var big = html.get(url);
callback(big);
big = null; // this isn't going to get erased until after big is done is it?
Run Code Online (Sandbox Code Playgroud)
这就是我尝试过的:
var big = html.get(url);
process.nextTick(function() {callback(big)}); // this seems wrong to me.
big = null;
Run Code Online (Sandbox Code Playgroud) 试图弄清楚这是怎么可能的......
$(function() {
$('#saveBtn').click(save());
});
function save(){
alert('uh');
}
Run Code Online (Sandbox Code Playgroud)
.
<form id="video-details" method="post" action="">
<input id="saveBtn" class="submit" type="submit" name="submit" value="Submit Video" disabled/>
</form>
Run Code Online (Sandbox Code Playgroud)
我在save()函数上设置了一个断点,它由列出click事件的行上的匿名函数调用.然而,这是直接在加载时发生的,更不用说输入开始不可见和禁用,因此无法单击它.
我将click函数更改为存在且不存在的不同元素,无论我做什么,该函数仍会在页面加载时触发.
不确定在哪里调查其原因,但我认为这不是正常行为
所以我将所需的每个文件链接到index.html文件中:
<script src="jquery.js"></script>
<script src="notify.js"></script>
<script src="script.js"></script>
Run Code Online (Sandbox Code Playgroud)
我在'notify.js'中创建了一个对象:
var notify = {
newNotification : function(text) {
}
}
Run Code Online (Sandbox Code Playgroud)
script.js:
alert(notify.newNotification);
Run Code Online (Sandbox Code Playgroud)
当我尝试访问'script.js'中的'notify'对象时,它工作正常.但我想使用jquery所以我将$(document).ready()添加到这两个文件中:
notify.js
$(document).ready (
function() {
var notify = {
newNotification : function(text) {
}
}
}
)
Run Code Online (Sandbox Code Playgroud)
的script.js:
$(document).ready (
function() {
alert(notify.newNotification);
}
)
Run Code Online (Sandbox Code Playgroud)
在我添加之后,它出现了未定义的通知.出了什么问题?任何人都可以解释为什么它不起作用?
Eloquent Javascript一书的第17章中的一个练习是实现Promise.all()方法,我想出了这个实现(它不起作用):
function all(promises) {
return new Promise(function(success, fail) {
var successArr = new Array(promises.length);
if (promises.length == 0)
success(successArr);
var pending = promises.length;
for (var i = 0; i < promises.length; i++) {
promises[i].then(function(result) {
successArr[i] = result;
pending -= 1;
if (pending == 0)
success(successArr);
}, function(error) {
fail(error);
});
}
});
}
// Testing
function soon(val) {
return new Promise(function(success) {
setTimeout(function() { success(val); },
Math.random() * 500);
});
}
all([soon(1), soon(2), soon(3)]).then(function(array) {
console.log("This …Run Code Online (Sandbox Code Playgroud) 这是我的循环代码
var username = ['Sam', 'Adarsh', 'Rohit', 'Rajat'];
for(var i in username){
console.log(username[i]);
}
Run Code Online (Sandbox Code Playgroud)
它根据需要输出相同,但我不确定为什么需要声明.我理解VAR和LET的概念,但不确定var在哪些情况下会在for循环中产生问题?
任何身体请帮助我理解这个概念.我是新的菜鸟,试图找出:)
谢谢你的帮助.
我需要从8个不同的URL获得8个JSON.我存储了我必须在数组中更改的查询字符串,并使用for循环遍历它.这是我的代码:
var index = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
var request = new XMLHttpRequest();
for (var i = 0; i < index.length; i++) {
var url = "https://wind-bow.glitch.me/twitch-api/channels/" + index[i];
request.open("GET", url);
request.onload = function() {
var data = JSON.parse(request.responseText);
console.log(data);
}
request.send();
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我只想在控制台上显示每个JSON.我没有收到任何错误,但我只能显示最后一个带有最后一个索引项的JSON(noobs2ninjas).
谁能解释一下为什么?我如何获得我需要的所有JSON?
谢谢
我不知道内部函数如何从.sort()方法传递参数.我知道.sort()传递值createComparisonFunction(),但它们如何最终在内部函数中?它只是从外部函数中获取任何未使用的参数吗?
我想了解这种行为.
function createComparisonFunction(propertyName) {
return function(object1, object2){
var value1 = object1[propertyName];
var value2 = object2[propertyName];
if (value1 < value2){
return -1;
} else if (value1 > value2){
return 1;
} else {
return 0;
}
};
}
var data = [{name: "Zachary", age: 28}, {name: "Nicholas", age: 29}];
data.sort(createComparisonFunction("name"));
alert(data[0].name); //Nicholas
data.sort(createComparisonFunction("age"));
alert(data[0].name); //Zachary
Run Code Online (Sandbox Code Playgroud)