小编T.J*_*der的帖子

条件运算符值的sizeof?:

#include <stdio.h>  
int main()  
{ int x = 1;    
short int i = 2;   
float f = 3; 
  if(sizeof((x == 2) ? f : i) == sizeof(float))    
  printf("float\n");  
  else if (sizeof((x == 2) ? f : i) == sizeof(short int))     
  printf("short int\n");    
}  
Run Code Online (Sandbox Code Playgroud)

这里的表达式((x == 2) ? f : i)计算i类型为short int的类型.. short int = 2的大小,而sizeof float是4 byts.output应该是"short int"但是我得到输出"float"

c

-1
推荐指数
1
解决办法
460
查看次数

为什么在使用getElementById时会收到“ TypeError:无法读取null的属性'value'”的信息?

在下面的代码中:

function Transact() {
    if(document.getElementById('itctobuy').value!='') {
        itctobuy = parseInt(document.getElementById('itctobuy').value);
    }
    if(document.getElementById('steamtobuy').value!='') {
        steamtobuy = parseInt(document.getElementById('steamtobuy').value);
    }
    if(document.getElementById('reltobuy').value!='') {
        reltobuy = parseInt(document.getElementById('reltobuy').value);
    }
    if(document.getElementById('airtobuy').value!='') {
        airtobuy = parseInt(document.getElementById('airtobuy').value);
    }
    if(document.getElementById('bsnltobuy').value!='') {
        bsnltobuy = parseInt(document.getElementById('bsnltobuy').value);
    }
    updateValues();
}
Run Code Online (Sandbox Code Playgroud)

该功能由一个简单onclick的按钮执行。有5个textarea元素,用户可以输入任意数字,如果textarea值不为空,则单击按钮时,值应存储在这些变量中(尽管即使不为空,也不能使用)当下)。
如果我删除了整个块,则updateValues()可以很好地执行,而将其放回原位将导致它无法执行,因此问题就出在这里。这是什么原因,我该如何解决?

编辑:控制台显示以下内容:

未被捕获的TypeError:在HTMLButtonElement.onclick上的TRANSACT无法读取null的属性“值”

那么,此错误的原因是什么?当我输入所有文本字段并且它们的值不为null时,它不起作用。

javascript function

-1
推荐指数
1
解决办法
5194
查看次数

返回语句执行后无法理解流程

我遇到了这段代码的问题:

function foo(i) {

  if (i < 0) {

    return;
  }
  console.log('begin:' + i);
  foo(i - 1);
  console.log('end:' + i);
}
foo(2);
Run Code Online (Sandbox Code Playgroud)

begin:2
begin:1
begin:0
end:0
end:1
end:2
>>undefined

不知道为什么

end:0  
end:1
end:2

正在控制台上打印.

返回语句后执行值再次为正.为什么会这样?

javascript recursion

-1
推荐指数
1
解决办法
50
查看次数

jQuery hover()第二个回调

我有一个div带有类名的元素event-element.当我悬停元素时,我希望它显示文本"鼠标悬停!".当我点击该元素时,我希望它显示"Clicked!" 到目前为止,我使用以下代码:

$(document).ready(function() {
    $('.event-element').hover(function(event) {
        $('.event-element').text("Mouse Over!");
    });
    $('.event-element').click(function(event) {
        $('.event-element').text("Clicked!");
    });
});
Run Code Online (Sandbox Code Playgroud)

但是,在第二次悬停回调时,我需要显示"Mouse Left!"的文字.暗示鼠标不再悬停在元素上.任何有关如何使这项工作的建议表示赞赏.

html javascript jquery

-1
推荐指数
1
解决办法
257
查看次数

如何使用 onClick 从 JSX 组件向反应函数组件传递参数

这是我的大代码中的一个非常小的片段:

import React from "react";
const Home = () => {
    return (
      imgFilter.map((imgs) => {
        return ( <
          Col sm = "3"
          xs = "12"
          key = {
            imgs.id
          }
          className = "trend-image" >
          <
          img src = {
            imgs.path
          }
          alt = {
            imgs.id
          }
          className = "img-fluid"
          onClick = {
            Price
          }
          /> <
          /Col>
        )
      });
    }
Run Code Online (Sandbox Code Playgroud)

在这段代码中,您可以在一行中看到它是这样写的onClick={Price}。这里的 Price 是我正在导入的一个函数组件。现在,Price 旨在接受争论。在这里,我想在imgs.id单击图像时将价格传递给价格。我该怎么做

javascript jsx reactjs

-1
推荐指数
1
解决办法
97
查看次数

打字稿中类和对象之间的区别

有人可以解释我打字稿中的类和对象有什么区别。

class greeter{
  Name: string;
  Sayhello(){
    console.log("hello")
  }
}
Run Code Online (Sandbox Code Playgroud)

在我使用这个之前

var greeter = {
    Name : "",
    Sayhello: function sayhello(){
        console.log("hello");
    }
}
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-5 typescript

-2
推荐指数
2
解决办法
1401
查看次数

意外的令牌}但仅限于较早版本的webview,而不是较新的版本

Uncaught SyntaxError: Unexpected token }在Android 4.4的webview上获取此代码,但相同的代码适用于Android 5.0或更高版本.

是什么让旧版webview版本失败?

function isyeriekle(satkir) {
    var ilanbasligi = $("input[name='ilanbasligi']").val();
    var ilanfiyati = $("input[name='ilanfiyati']").val();
    var mkare = $("input[name='mkare']").val();
    var binayasi = $("input[name='binayasi']").val();
    var klnmdrm = $("input[name='durumu']").val();
    var ilannotlari = $("#ilannotlari").val();
    var ilanfotolari = $('#list').html();


    if ($.trim(ilanbasligi) == '' || $.trim(ilanfiyati) == '' || $.trim(mkare) == '' || $.trim(klnmdrm) == '' || $.trim(ilannotlari) == '' || $.trim(binayasi) == '') {
        myApp.alert('Bir veya daha fazla kutucuk bo? görünüyor...');
    }
    else {
        myApp.showPreloader('?lan kaydediliyor...');
        $.post(sunucuurl + …
Run Code Online (Sandbox Code Playgroud)

javascript jquery cordova

-2
推荐指数
1
解决办法
246
查看次数

JavaScript while循环条件变量未更新

为什么以下逻辑不起作用?

警告:当您单击"运行代码段"时,以下内容将启动无限循环.

var i = 0;
var currentLocation = 1;

while(currentLocation !== 9){
    console.log(currentLocation);
    currentLocation += i;
    i++;
}
Run Code Online (Sandbox Code Playgroud)

这进入了一个无限循环.但是如果我们替换currentLocation += i;currentLocation++;,它按预期工作.只是好奇为什么会这样.

javascript increment while-loop

-2
推荐指数
1
解决办法
43
查看次数

尽管字符串相同,.equals方法返回false

我正在尝试做一个回文计划.我是初学者.这是我的代码:

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    // palindrome

        System.out.println("Enter a statement");
        Scanner scan = new Scanner(System.in);
        String userInput = scan.nextLine();
        StringBuilder str;
        str = new StringBuilder(userInput.replace(" ", "").toLowerCase().trim().toString());
        System.out.println(str);
        String reversed = new StringBuilder(str).reverse().toString().trim();
        System.out.println(reversed);

        if(str.equals(reversed)){
            System.out.println("is palindrome");
        }else{
            System.out.println("not a palindrome");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我试过调试模式和一切.不知道为什么它不返回回文.

java string

-2
推荐指数
1
解决办法
40
查看次数

如何在 Kotlin 中创建对象列表?

我在 Java 之后开始使用 Kotlin。

我想写一个函数来返回 Single<List<LocationData>>

override fun getDestinations(): Single<List<LocationData>> {
  //return ???
}
Run Code Online (Sandbox Code Playgroud)

我的LocationData班级:

@Parcelize
data class LocationData(val latitude: Double, val longitude: Double) : Parcelable
Run Code Online (Sandbox Code Playgroud)

如何在 Kotlin 中创建List静态LocationData对象?

在 Java 中,我会这样做:

override fun getDestinations(): Single<List<LocationData>> {
  //return ???
}
Run Code Online (Sandbox Code Playgroud)

kotlin

-2
推荐指数
2
解决办法
7045
查看次数